Posts

Showing posts from April, 2013

How to work with JSON in Android

Image
In this post I'll describe a way to work with JSON in Android. . First of all, what is JSON. JSON is short for JavaScript Object Notation and it is an independent data exchange format. Data structures in JSON are based on key / value pairs and we can summarize in these points: JSON Object : { string : value , .... } JSON Array : [ value , value .....] value : string || number || object || array || true || false, || null If you observe normally JSON data will have square brackets and curly brackets. The difference between [ and { is, the square bracket represents starting of an JSONArray node whereas curly bracket represents JSONObject. This is an example: { "id":10, "name":"myname", "listMessages": [ { "value":1, "text":"value", "id_message":0 }, { "value":11,"text":"value","id_message":1} ] }

Restore sms from Google Drive

In previous post I described how to backup sms in Google Drive. In this post I will try to restore sms from a backup saved in Google Drive, and I will also use the new app data folder . As always, it is just an example. It is quite simple, but pay attention , you will write your SMS Content Provider. In order to backup sms, in our app we can do these steps: Choose a Google Account through AccountPicker.newChooseAccountIntent() . Search for a backup file from Google Drive Parse the backup file Update Sms Content Provider In our example we will search our backup file in a Google Drive folder or in appdata folder. . Files.List request = mService .files() .list() .setQ("mimeType = '" + MIME_TEXT_PLAIN + "' and '" + folderId + "' in parents "); If you want to use appdata folder, folder

Backup sms in Google Drive

Image
In previous post I described how to make simple actions with Google Drive from own apps. In this post I will try to do a simple sms backup in a google drive folder, and I will use the new app data folder . It is a quite simple operation.If you've already understood how to use Google Drive, the only difficulty is to find a way to retrieve sms from your device. There are many implementations on the web, but there are not public API. I choose to use TelephonyProviderConstants that you can find in the awesome DashClock app. First of all we have to do these steps described in previous post: Enable the Drive API from Google API Console Add Drive API v2 to your project Make sure the Google Play Services client library is being included in the Android's project build path Then,in order to backup sms, in our app we can do these steps: Choose a Google Account through AccountPicker.newChooseAccountIntent() . Create a Folder in Google Drive Read sms from device Crea

Simple actions with Google Drive API v2

Image
In this post I'll describe how to make simple actions with Google Drive from own apps. First of all you have to do these steps: Enable the Drive API from Google API Console Add Drive API v2 to your project Make sure the Google Play Services client library is being included in the Android's project build path You can find official doc here . It is very simple. Now we can try to use API. In order to use Google Drive, we have to choose a Google Account . It is very easy, and I described it in a previous post. In a real app, you can save your account in preferences. CREATE A FOLDER When we use Google Drive API, we have to get a token. We can use this code: private void initService() { mCredential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE); if (mAccountName != null) { mCredential.setSelectedAccountName(mAccountName); mService = getDriveService(mCredential); } } private Drive getDriveService(GoogleAccountCredenti