Post on 15-Jan-2015
description
Google Integration in Android AppsRonan Schwarz and Friedger Müffke
Moosecon - 8 March 2013
Android and Google
● Android Open Source Project (AOSP)all, cheap, free
● Open Handset Alliance84 companies, Google governance
● Android Update Alliancepromise to update
● Google User ExperienceCTS and relevance
Google for developers so far
● Some Content Provider API, e.g. calendar contract
● Intents to launch appse.g. Navigation
● Java libs and Web APIse.g gdata client lib to connect to Google Docs
Google Play Framework (gms)
● Requires Android 2.2 and Google Play
● APK that provides APIs to Google services
● Service APK will and must be installed automatically
Google Play Framework (gms)
Requires real device
Helper methods
● Always check for availability first!
● Use isGooglePlayServicesAvailable() in onResume
● Give the user a chance to install the missing file with getErrorDialog()
● getOpenSourceSoftwareLicenseInfo()
Authentication
http://www.flickr.com/photos/carlosluzz/
Authentication
● OAuth2 through GoogleAuthToken class
● get the Google Account(s) by○ AccountManager
○ AccountPicker.newIntent()
● Email needed for retrieving auth token
● getToken() for UI components
● getTokenWithNotification() for Services
Authentication Error Handling
● User Recoverable Error○ UserRecoverableAuthException
○ GooglePlayServicesAvailabilityException
○ UserRecoverableNotifiedException
● Non-Recoverable Error○ GoogleAuthException
Google Plus
Google Plus
● Updated on 26 February 2013
● Policy ○ not to misuse personal data and +1 links○ only use Google provided branding○ provide means to revoke authorization
Google Plus: Setup
ServicesOAuth2 client
Google Plus: Setup
Identify each client
PlusClient: initialize
PlusClient.Builder()...build()
PlusClient.connected() and .disconnected() within component lifecycle
All calls are asyncronous .onConnected() and .onDisconnected()
PlusClient: Sign-In
● Visual user consent <com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button" android:layout_width="wrap_content" android:layout_height="wrap_content" />
● startResolutionForResult() on click
● optional sign-out button● required revoke method with deletion of data
PlusClient: Social Graph
● Profile of the user mPlusClient.loadPerson(this, "me"); // or "108591961893121462921"
● People in the circles of the usermPlusClient.loadPeople(this, Person.Collection.VISIBLE);
● Email address (PlusClient.getAccountName()) requires additional permission GET_ACCOUNTS
PlusClient: App Activities
AddActivityBuyActivityCheckInActivityCommentActivityCreateActivityDiscoverActivityListenActivityReserveActivityReviewActivityWantActivity
● Moments: "possibility to share what user has done in the app"
● Prepare snippet
(or let prepare) ● writeMoment(moment)
● removeMoement(moment)● listMoments()
PlusShare: Share Content
● Simple share intent PlusShare.Builder.getIntent()
● Deep linking setContentDeepLinkId() setContentUrl()
● Interactive posts
addCallToAction() ● Can be ActionBar or (standard) Button● Breaks ShareActionProvider
PlusShare: Deep Linking
● Intent filter in Manifest<activity android:name=".ParseDeepLinkActivity"> <intent-filter> <action android:name="com.google.android.apps.plus.VIEW_DEEP_LINK" /> <data android:scheme="vnd.google.deeplink" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter></activity>
● Extract deep link idPlusShare.getDeepLinkId(this.getIntent());
PlusOneButton: Recommendations
● Add a +1 Button to anything <com.google.android.gms.plus.PlusOneButton xmlns:plus=
"http://schemas.android.com/apk/lib/com.google.android.gms.plus" plus:size="standard"/>
● One URL per buttonmPlusOneButton.initialize(mPlusClient, URL);
● No Meta-Data
Over-the-air install (7 March)
● Setup web client
● Sign-in Button + app package name
● Quality control by Google (?)
Google Maps: V2
Google Maps: V2
● Fragments!
● Fragments for older Devices!
● Views!
● Activities ?
● Breaks compatibility.
Google Maps: Camera
● 2-Axis Rotation
● Perspective View
● Zoom
● Move
● Target
Google Maps: Markers
● Default Markers
● Customize
Appearance
● Show InfoWindow
● InfoWindow != View
● Add/Remove
Markers manually
Google Maps: Custom Drawing
● Lines
● Circles
● Polygons
● Points are Lat,Long pointsPolygon polygon = map.addPolygon(
new PolygonOptions() .add(new LatLng(0, 0), new LatLng(0, 5), new LatLng(3, 5)) .strokeColor(Color.RED) .fillColor(Color.BLUE));
Goodies
http://www.flickr.com/photos/g-alain/
ImageManager
● Load Images from an external resource in
the background
● Can specify a default resource for errors etc
● As easy as loadImage(ImageView,Uri,defaultResId)
● Only G+ URL's
● For everything else use the novoda
ImageLoader on github.com/novoda
PanoramaClient
● Load from URL
● Load from ContentProvider
● Zoom and Rotate
Hints
● Debugadb shell setprop log.tag.GooglePlusPlatform VERBOSE
● Lot's of example codes and documentation at https://developer.android.com/google/play-services/index.html
● G+ Bootcamp for companieshttp://googleplusplatform.blogspot.de/2013/03/global-google-sign-in-bootcamps.html
Berlin, Germany - March 18th - March 22nd
More to come...
Questions
Ronan SchwarzFriedger Müffke
novoda.com@novoda#moosecon