How to Grow Your Audience With Google App Invites

Final product image
What You'll Be Creating


One of the most effective marketing tools is definitely word of mouth. Social proof is a very powerful stimulus when it comes to decision making. While people easily ignore traditional advertising, few people tend to ignore advice from a trusted source, such as a friend.

In 2011, Google and Ipsos OTX carried out a survey that revealed interesting results. If recommendations are complemented by discount coupons that recipients can redeem, the probability that they will download the app or will start to use it again are much higher. This is something developers and app publishers may want to keep in mind.

The truth is that very few mobile app publishers and developers make use of a referral system that is based on recommendations. The reason is almost always technical. Keeping track of discount codes, implementing deep linking within apps, and setting up a backend are some of the hurdles developers need to take to make this work. As a result, most people don't bother or give up.

Fortunately, Google developed a system that overcomes these obstacles, App Invites. With App Invites, Google offers a powerful interface through which developers can grow their mobile app's audience by letting existing users invite their contacts to try the app.

App Invites is included in Google Play services and is also available on iOS. It optimizes your app install rates by reducing friction and providing some context, such as the app's general information and its rating on the app store, at every step of the user invitation flow.

In this tutorial, I will show you how to implement this powerful tool in your own Android application.

1. Project Setup

Step 1: Create the Project 

I will use a very simple project to show you how to share invites for your app. The first thing you need to do is create a new project. In Android Studio, choose File > New > New Project. Name your app and set your company's web domain to let Android Studio define the package name of your app.

The minimum SDK version that the app can support can be as low as Android Gingerbread (API level 9). This means that you can target almost every device running Android, 99.97% at the time of writing. However, keep in mind that App Invites only work on devices that include Google's Play store since it is based on the Google Play services plugin.

Generate a blank Activity and name it

Step 2: Add Google Play Services and Support Libraries

With the new project opened in Android Studio, open the Project tab on the left and expand Gradle Scripts. It contains two files with the same name, build.gradle. The first file is the top-level build.gradle. The second file is the app-level build.gradle.

Gradle Scripts on Android Studio

Open the top-level build.gradle and add the following classpath for Google Play services.

Open the app-level build.gradle and add the following compile dependencies to it.

To enable the Google Play services plugin, add the following line below apply plugin: ''.

Android Studio will ask you to synchronize the project files. Before you do, however, open AndroidManifest.xml and add the Google Play services version within the application tag.

Save the changes and click Sync Now. We're not done yet. Android Studio will throw an error that tells you that the Google Play services plugin requires a configuration file, google-services.json. Let's fix that now.

Google Services plugin error

2. Add Configuration File

Step 1: Visit Google Developer Platform

You frist need to visit the Google Developers website to enable Google services for your app. The project is then added to your personal developer console, which means that you have to be authenticated as a Google user before proceeding.

Enter the name you chose for your app and specify its package name. If you don’t remember the app's package name, then open the app-level build.gradle. You can find it under defaultConfig > applicationId.

Fill out the rest of the form and click the button at the bottom labeled Choose and configure services.

Google Developer platform

Step 2: Generate Certificate Fingerprint

The next part is a bit trickier. Google will ask you for the certificate fingerprint. To obtain the certificate fingerprint, you need to open the command line and execute the following command.

There are two possible scenarios:

If you're testing your app locally, the key name is androiddebugekey and its default location is %USERPROFILE%\.android\debug.keystore on Windows and ~/.android/debug.keystore on Unix systems, such as OS X and Linux. This is what the command looks like for testing locally.

The keytool utility will prompt you to enter a password. The default password for the debug keystore is android. This will yield the SHA1 fingerprint of your debug certificate, which looks something like this.

However, if you need the release certificate fingerprint, then you need to specify the certificate's name, location, and password.

App Invites on Google Developer platform

Step 3: Add Configuration File

After entering the certificate fingerprint, you can enable App Invites by clicking the Enable App Invites button at the bottom. You should now be able to download the configuration file by clicking Download google-services.json.

To complete this step, copy the downloaded file to the app/ or mobile/ directory of your project.

Google Services plugin configuration file

3. Sending Invitations

Step 1: Define Layout

With the project configured, we are ready for the next step. For the launcher Activity, define a simple layout like the one shown below. It contains a button and a label.

The result should look like this.

Launch Activity Layout

In the onCreate method the MainActivity class, add an onCreateListener to the button.

The invitation will be sent as an Intent. You can specify a message that users can customize before sending the invites to their friends. You can also set a call to action, a background image, and a deep link that your app can handle once the invitation is received. You can even define the minimum SDK version (setAndroidMinimumVersionCode) and a target application ID for other platforms, such as iOS (setOtherPlatformsTargetApplication).

Create the Intent in the body of the onClick method.

Add the following strings to make all this work.

That's all there is to it. When the Intent is started, a custom Activity shows up that lets the user choose how they'd like to send the invitation (email or text message), the message of the invitation, and the recipients.

Google App Invites invitation screen

The intent is started by calling startActivityForResult. It is possible to fetch the result of the intent. Once the user has hit the send button, they are brought back to the activity that started the intent. At that moment, you can do whatever is necessary in onActivityResult, such as hiding the button or tracking invites through analytics.

4. Deep Linking

Step 1: Send Deep Link Data

When a user receives the invitation and clicks the included link, the invitation flow branches according to whether or not the app is already installed on the recipient's smartphone. If the app is already present, it will automatically receive an Intent containing the optional deep link data.

However, if the recipient doesn't have the app installed installed, they are given the chance to do so. When the app is first launched, the app will receive an Intent containing the deep link data. This way, the discount you may want to provide will always be available to the recipient. This overcomes the issues we talked about earlier.

Let's explore deep linking in more detail. Set the deep link of the Intent we created in the onCreate method.

Step 2: Intent Filtering for Custom URLs

The first thing you need to do to handle custom deep links is telling your app how they are made and which Activity should take care of them. Add a new Activity to your project and name it DetailsActivity.

Open AndroidManifest.xml and add the following snippet to the <activity android:name=".DetailsActivity"> tag.

We are telling the system the following. If it invokes the action VIEW on a URL whose scheme is tutsplus and whose host is, your app can handle it using the DetailsActivity class.

In order to receive and parse the custom URL, you first have to create an auto-managed GoogleApiClient with access to App Invites. We do this in the onCreate method of the MainActivity class.

Step 3: Receiving and Parsing the Deep Link

To check for invitations and to launch the deep link Activity, you can use the getInvitation method, which was introduced in Google Play services 8.3. Add the following code snippet to the onCreate method of the MainActivity class.

Setting the last parameter of the method to true tells the plugin to automatically call the activity responsible for handling the deep link, the DetailsActivity class in our example. This is the reason why the body of the onResult method is empty.

Open activity_details.xml and add two TextView objects like shown below.

Next, open DetailsActivity and override the onStart method. To check if the Intent contains deep link data, you have to rely on the hasReferral method. The URL parsing is very straightforward as you can see below.

Google App Invites deep linking


In this article, you learned how to implement Google's App Invites in your app, using the Google Play services plugin. This tool lets you increase the audience of your app by allowing users to send invitations to their Google contacts. You should now be able to develop a referral system by leveraging App Invites, letting your users recommend your app to their friends using personalized, contextual invitations.



Related Articles