Posts

Showing posts with the label Google Play Services

GPlayServices #1: Save to Google Drive

Image
A little snippet to save a file (or some contents) in Google Drive with the Drive API included in the Google Play Services . To use the Google Drive API we have to follow these steps:(this blog doesn't cover these topics) : Set Up Google Play Services SDK Register your app in Google Developers Console to activate the API Now we can build our code. First of all, we have to create an instance of GoogleApiClient using the GoogleApiClient.Builder and implementing the callback interfaces to manage the connection and the authorizations as described in GPlay Service #0 . Our scope is to save a file (an image) choosing a folder in Google Drive. To choose a folder inside our Google Drive we can use the Drive.DriveApi.newOpenFileActivityBuilder() . This method creates a builder for an Open File activity that allows user selection of a Drive file. Upon completion, the result Intent will contain the DriveId for the selected file. We can use the OnConnected interface to know...

GPlayServices #0: Configure the GoogleApiClient with Google Play Services.

Image
A little snippet to connect your app with the Google Play Services API. To use the Google Play Services API you have to follow these steps:(this blog doesn't cover these topics) : Set Up Google Play Services SDK Register your app in Google Developers Console to activate the API Now you can build your code. First of all, create an instance of GoogleApiClient using the GoogleApiClient.Builder. /** * Called when activity gets visible. A connection to Drive services need to * be initiated as soon as the activity is visible. Registers * {@code ConnectionCallbacks} and {@code OnConnectionFailedListener} on the * activities itself. */ @Override protected void onResume() { super.onResume(); if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addScope(Drive.SCOPE_APPFOLDER) ...

Snippet: Google Picker Account

Image
If we want to show a picker with Google accounts, it has become extremely simple with Google Play Services. Until a few months ago, we would have had to use something like this: AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE); Account[] list = manager.getAccounts(); for(Account account: list) { if(account.type.equalsIgnoreCase("com.google")) { //Do something } } To use this code we need the following permission in your manifest: Now we can use new AccountPicker.newChooseAccountIntent() method. First of all, we need to make sure the Google Play Services client library is being included in the Android's project build path. Select Project > Properties > Java Build Path > Libraries from the Eclipse menu. Click Add External JARs. Browse to android-sdk-folder/extras/google/google_play_services/libproject/google-play-services_lib/libs, select google-play-services.jar and click OK. In the Order and Ex...