Adding deep linking to Google+ posts shared from your Android app

Deep linking allows the Google+ app on mobile devices to direct clicks on a shared post that contains deep-link information to a resource within your mobile app if the user has it installed. If the user does not have your app installed, they are prompted to install it before accessing the resource. Deep linking can be used on shared basic posts and shared interactive posts.

When your users share from your app, you can enhance the links that they share so that when people follow the link or call-to-action button on any platform (Android, iOS, or desktop), they can launch your app in the appropriate context. For this cross-platform deep linking to work, you will create a client ID for each platform in the same Google Developers Console project and modify your apps to write deep links and to handle incoming deep links.

1. Enable deep linking for each supported platform

  1. Go to the Google Developers Console.

  2. Select the project you created in Start integrating into your Android app. The OAuth 2.0 client ID for Android that you created in this project will be used in step 2b.

    1. Select APIs & auth > Credentials.

    2. To enable deep linking, select Edit settings for the client ID for Android from step 2 above, then select Enabled in the Deep Linking section of the dialog.

    3. Select Update to save your change.

    4. If you are supporting additional platforms (iOS or Web), create a client ID for each platform in this same Developers Console project. If you are creating an iOS app, enable deep linking for that client ID.

If you specify a URL to a logo for your app in the Consent Screen section, your logo might be displayed in any post to help users identify the origin and target of the post. By using the sharing feature, you agree that Google can display the name of your app and your logo within Google's products and services.

Deep links require an identifier that your app defines for use across its supported platforms to identify the correct deep-link view to launch in your app. In addition, for content deep links you must either specify a URL from which Google will retrieve the content to render the share preview, or specify data for the title, description, and thumbnail URL.

You can build content deep links in two ways:

  • Specifying a URL as the deep-link identifier. If you have a web presence that you can link to, you should use that URL for both the content URL and the deep-link identifier so that Google can retrieve the snippet data for you to use in the shared post.

  • Specifying a URI path as the deep-link identifier and passing the title, description, and thumbnail URL in a bundle. Choose this approach when you do not have a URL to retrieve the information to populate the share dialog.

The deep-link identifier must be 512 or fewer characters, and should not contain any invalid characters or character sequences for a URL. This could be any arbitrary string, or a fully qualified URL, depending on your application's needs. For example, "HelloWorld", "4815162342" or "http://example.com/mobiledata/4815162342/" are all considered valid deep-link identifiers, but not "hello world" (space) or "hello%2Xworld" (bad escape sequence). If you are using an arbitrary string for your deep-link identifier, you might consider base64-encoding it to ensure it contains only valid characters.

3. Sharing with deep linking

Configure the URL and deep-link identifier. If you do not have a URL that identifies a web representation of the resource that you are trying to link to, you can use a URI path identifier and populate the share snippet details.

Using a full URL identifier

Intent shareIntent = new PlusShare.Builder(this)
        .setText("Check out: http://example.com/cheesecake/lemon")

startActivityForResult(shareIntent, 0);

The data used for the Google+ snippet is extracted from http://example.com/cheesecake/lemon.

When a user clicks on a shared post that contains deep-link data for your app, the app launches if installed, or the user is prompted to install your app. The Google+ app directs deep links to the appropriate app based on the platform that the user is browsing. For example, if they are using iOS and you have an iOS app registered in the Developers Console, the Google+ app will launch your iOS app and pass the deep-link identifier, which your app can use to direct the user to the correct location within your app. These deep links work across platforms: an interactive post generated from your Android app can launch your iOS app on an iOS user's device.

When the app launches, it needs to check if the deep-link information is available and launch the correct view in the app.

  1. To configure your app to start listening for deep links, update your AndroidManifest.xml file with the following:

    <activity android:name=".ParseDeepLinkActivity">
            <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" />
  2. Next, add the ParseDeepLinkActivity activity to your app. This activity accepts a deep-link ID, and routes it to the correct Android Activity. In this case, because the deep link is /pages/create, we route to the CreatePageActivity:

    public class ParseDeepLinkActivity extends Activity {
        protected void onCreate(Bundle savedInstanceState) {
            String deepLinkId = PlusShare.getDeepLinkId(this.getIntent());
            Intent target = parseDeepLinkId(deepLinkId);
            if (target != null) {
         * Get the intent for an activity corresponding to the deep-link ID.
         * @param deepLinkId The deep-link ID to parse.
         * @return The intent corresponding to the deep-link ID.
        private Intent parseDeepLinkId(String deepLinkId) {
            Intent route = new Intent();
            if ("/pages/create".equals(deepLinkId)) {
                route.setClass(getApplicationContext(), CreatePageActivity.class);
            } else {
                // Fallback to the MainActivity in your app.
                route.setClass(getApplicationContext(), MainActivity.class);
            return route;

Next steps

Send feedback about...

Google+ Platform for Android
Google+ Platform for Android