One of the most common features that we usually implement in our apps is the ability of the user to share the app with friends.
This is a great way to make our app grow and a free mechanism of user acquisition.
Normally we have implemented this functionality with some kind of custom message and allowing the user to send it by email, text message, etc.
With App Invites we not only can share the app but also send deep links, customised invite cards, link with Google Analytics to track the flow, etc.
Integrating the API
So lets start to set up our project adding the Google Play Services metadata in the app manifest:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Then we need to add the dependency to our top-level build.gradle:
and also apply the gsm plugin to our app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
Finally we add the Google Play Services dependency in the app’s Gradle file:
Right, next thing we need to add to our project is a Json configuration file that we will get from Google that provides service information specific to our app.
To do this we will have to add in the Google Developer Console our application package name and the SHA1 key from our key store. Click here to access the dev portal to do so.
Once we have the configuration google-services.json file we just need to copy it into the app/ or mobile/ directory of our project.
Sending an app invite
Ok, so now that we have finished the integration let’s do the funny part, and send an app invitation.
To achieve this we just need to build and start an Intent, something like this:
Intent intent = new AppInviteInvitation.IntentBuilder("Try this app!") .setMessage("Hey take a look to this awesome app that I'm using!") .build(); startActivityForResult(intent, REQUEST_INVITE);
If everything went well, when we launch our app and we launch this intent we should see a really nice interface that will show the user’s contacts list and the option to send the invite.
When the destination user receives the invite, depending on if he or she has installed the app different things might happens as we can see in the diagram below:
So that’s it! This is just an introduction but there are more interesting options to explore as the integration with Google Analytics, deep links features, etc.
You can find an example of the integration and use for Android in my examples project here. And as usual any comments and feedback are more than welcome!