29
Android Deep Linking www.letsnurture.com

Android Deep Linking

Embed Size (px)

DESCRIPTION

Android Deep Linking Explanation

Citation preview

Page 1: Android Deep Linking

www.letsnurture.com

Android

Deep Linking

Page 2: Android Deep Linking

www.letsnurture.com

Page 3: Android Deep Linking

www.letsnurture.com

Find the right app for you

Page 4: Android Deep Linking

www.letsnurture.com

Page 5: Android Deep Linking

www.letsnurture.com

ExampleHere's an intent that launches the Zxing barcode scanner app. It follows the syntax thus:

intent: //scan/ #Intent; package=com.google.zxing.client.android; scheme=zxing; end;

To launch the Zxing barcode scanner app, you encode your href on the anchor as follows:

<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>

Page 6: Android Deep Linking

www.letsnurture.com

What is App Indexing?App Indexing allows you to connect pages from your website with specific content within your smartphone app.

This enables smartphone users who have your app installed to open it directly from relevant mobile search results on Google.

For example, imagine you run a recipe website and have an app that can also show your recipe.

Thanks to the app indexing feature, when a Google searcher on a mobile device is shown one of your recipes as a search result, they will now be able to open that result directly in your app if they have it installed.

Page 7: Android Deep Linking

www.letsnurture.com

Here is how to specify a deep link to your app content:

• In your Android manifest file, add one or more <intent-filter> elements for the activities that should be launchable from Google Search results.

• Add an <action> tag that specifies the ACTION_VIEW intent action.

• Add a <data> tag for each data URI format the activity accepts. This is the primary mechanism to declare the format for your deep links.

Page 8: Android Deep Linking

www.letsnurture.com

• Add a <category> for both BROWSABLE and DEFAULT intent categories.

– BROWSABLE is required in order for the intent to be executable from a web browser. Without it, clicking a link in a browser cannot resolve to your app and only the current web browser will respond to the URL.

– DEFAULT is not required if your only interest is providing deep links to your app from Google Search results. However, the DEFAULT category is required if you want your Android app to respond when users click links from any other web page that points to your web site. The distinction is that the intent used from Google search results includes the identity of your app, so the intent explicitly points to your app as the recipient — other links to your site do not know your app identity, so the DEFAULT category declares your app can accept an implicit intent.

Page 9: Android Deep Linking

www.letsnurture.com

<activity android:name="com.example.android.GizmosActivity" android:label="@string/title_gizmos" > <intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW" /> <!-- Accepts URIs that begin with "http://example.com/gizmos” --> <data android:scheme="http" android:host="example.com" android:pathPrefix="/gizmos" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity>

Page 10: Android Deep Linking

www.letsnurture.com

In this example, your app would respond to deep links such as 

http://example.com/gizmos?1234, http://example.com/gizmos/1234,http://example.com/gizmos/toys/1234, etc.

Page 11: Android Deep Linking

www.letsnurture.com

<activity android:name="com.example.android.GizmosActivity" android:label="@string/title_gizmos" >

<intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Accepts URIs that begin with "example://gizmos” -->

<data android:scheme="example" android:host="gizmos" /> </intent-filter> <intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Accepts URIs that begin with "http://example.com/gizmos” --> <data android:scheme="http" android:host="example.com" android:pathPrefix="/gizmos" /> </intent-filter> </activity>

Page 12: Android Deep Linking

www.letsnurture.com

• You can test your deep links using the Android Debug Bridge:

adb shell am start -a android.intent.action.VIEW -d "http://example.com/gizmos" com.example.android

adb shell am start -a android.intent.action.VIEW -d "example://gizmos" com.example.android

Make sure to test this on a fresh install of your app as well.• Use our deep link test tool to test your app behavior with deep

links on your phone. Alternatively, you can test your app's behavior in a browser by creating an HTML page with an intent:// link in it:

<a href="intent://example.com/gizmos#Intent;scheme=http;package=com.example.android;end;"> http://example.com/gizmos</a> <a href="intent://gizmos#Intent;scheme=example;package=com.example.android;end;">example://gizmos</a>

Page 13: Android Deep Linking

www.letsnurture.com

Restricting access to parts of your app contentres/xml/noindex.xml

<?xml version="1.0" encoding="utf-8"?> <search-engine xmlns:android="http://schemas.android.com/apk/res/android"> <noindex uri="http://example.com/gizmos/hidden_uri"/> <noindex uriPrefix="http://example.com/gizmos/hidden_prefix"/> <noindex uri="gizmos://hidden_path"/> <noindex uriPrefix="gizmos://hidden_prefix"/> </search-engine>

Page 14: Android Deep Linking

www.letsnurture.com

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.Gizmos"> <application> <activity android:name="com.example.android.GizmosActivity" android:label="@string/title_gizmos" > <intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW"/> ... </activity> <meta-data android:name="search-engine" android:resource="@xml/noindex"/> </application> <uses-permission android:name="android.permission.INTERNET"/> </manifest>

Page 15: Android Deep Linking

www.letsnurture.com

Connect your app to your website

• In order for Google to recognize your app as the official application for your website, you must connect your app to your website through the Google Play Console and Webmaster Tools. Please follow the steps listed here.

• After your app and your website are connected, if your app is using an HTTP scheme for handling deep links, Google will automatically start indexing the content of your app using URLs that Google has discovered through web indexing and that match the intent-filter patterns in yourAndroidManifest.xml file.

• After your app content is indexed without errors, deep links can appear in Google mobile search results automatically.

Page 16: Android Deep Linking

www.letsnurture.com

• If your app is using a custom URI scheme, you can still participate in App Indexing by specifying which deep links corresponds to your web pages using sitemaps, web annotations or the App Indexing API.

• Regardless of whether your web content is indexed automatically or not, we still recommend that you publish your deep links using sitemaps, web annotations or the App Indexing API as we will discuss next.

Page 17: Android Deep Linking

www.letsnurture.com

Add app deep links on your website

• Each page on your site can specify whether its contents should be loaded in your app. We offer several ways to tell Google about the relationship between a web page and a deep link to your app:

• Using a <link> element in the the <head> section of a page.

• Using an <xhtml:link> element in the Sitemap <url> element specifying the page.

• Using Schema.org markup for the ViewAction potential action.

• Using the App Indexing API.• Using the App Indexing API can also surface your app's

history in the Google app query autocompletions.

Page 18: Android Deep Linking

www.letsnurture.com

Format of the app URIs

• This <link> element specifies an alternate URI (specified in the href attribute) that can be used to open the content in your app. The format of the app URI is:

• android-app://{package_id}/{scheme}/{host_path}

Where:• package_id: application ID as specified in the Android

Play Store.• scheme: the scheme to pass to the application. Can be

http, or a custom scheme.• host_path: identifies the specific content within your

application.

Page 19: Android Deep Linking

www.letsnurture.com

Deep link App URI

http://example.com/gizmos?1234 android-app://com.example.android/http/example.com/gizmos?1234

http://example.com/gizmos/1234 android-app://com.example.android/http/example.com/gizmos/1234

http://example.com/gizmos/toys/1234 android-app://com.example.android/http/example.com/gizmos/toys/1234

example://gizmos?1234 android-app://com.example.android/example/gizmos?1234

example://gizmos/1234 android-app://com.example.android/example/gizmos/1234

example://gizmos/toys/1234 android-app://com.example.android/example/gizmos/toys/1234

Page 20: Android Deep Linking

www.letsnurture.com

Link rel=alternate elements in HTMLIn the HTML of the page http://example.com/gizmos, you add a <link> element as follows for the deep link http://example.com/gizmos:

<html> <head> ... <link rel="alternate" href="android-app://com.example.android/http/example.com/gizmos" /> ... </head> <body> … </body>

Or, if you're using a non-HTTP scheme (e.g., example://gizmo), you would add the following:

<html> <head> ... <link rel="alternate" href="android-app://com.example.android/example/gizmos" /> ... </head> <body> … </body>

Page 21: Android Deep Linking

www.letsnurture.com

Update robots.txt• When Google indexes content from your app, your app

will need to make any HTTP request that it usually makes under normal operation.

• However, these requests will appear to your servers as originating from Googlebot.

• Therefore, your server's robots.txt file must be configured properly to allow these requests. For example, your robots.txt file could include the following:

User-Agent: Googlebot Allow: /

• The app's behavior should not change because it or your server detects Googlebot. Consider network calls made from your app with Googlebot to be from a valid user.

Page 22: Android Deep Linking

www.letsnurture.com

AndroidManifest.xml

<application ... <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> ... </application>

Page 23: Android Deep Linking

www.letsnurture.com

Once your project is configured to use Google Play Services API, follow these steps for any activity that supports deep links:

• Create an instance of GoogleApiClient in the onCreate() method of your activity.

• Notify Google each time a new activity is viewed using the AppIndexApi.view() method. This can be called in the onStart() method of each activity.

• The view() should report the content that the user is currently looking at in your app. When that content changes, and the user is looking at something else, the app should call viewEnd() on the exiting content and then view() for the new content that is shown.

• The usual way this works is with onStart() and onStop() but it need not in the case of fragments or other scrolling-type UIs, for example.

• Disconnect your client in your onStop() method.

Page 24: Android Deep Linking

www.letsnurture.com

Best Practices

• Only call the AppIndexApi.view() method once each time the user explicitly chooses to view some content.

• There should be an existing deep link in the app for each API call.

• Use an accurate and descriptive title in your AppIndexApi.view() call. The text defined in this title may be used in the Google app query autocompletions.

• We recommend that you inform your users that links visited in the app may be shared with Google to improve the search experience.

Page 25: Android Deep Linking

www.letsnurture.com

Quality Guidelines• Google may take corrective action (e.g., demoting or removing your app

deep links from Google Search results and query autocompletions) in cases where we see abuse, deception, or other actions that hurt the search experience for our users. In particular, you should avoid:

• Calling the API on content the user is not viewing.• Calling the API more than once per user view.• Calling the API with a title that is misleading or incorrect.

• Note that Google may react to other misleading practices not listed here. The examples above are not exhaustive. Google may take action on other practices or techniques that hurt the search experience.

• Finally, once you have done everything in the launch checklist, Google will be able to start indexing your app. You can check for any issues that arise in Webmaster Tools.

Page 26: Android Deep Linking

www.letsnurture.com

App Indexing Checklist

Android app• App supports deep linking and the manifest file describes an intent filter

with the action android.intent.action.VIEW, and has the categories android.intent.category.BROWSABLE and android.intent.category.DEFAULT.

• App deep link implementation has been tested by running the command "adb shell am start [deep link]" or by using the deep link test tool on a fresh app install with an Android device.

• Tapping the BACK button after opening a deep link leads you back to the previous screen.

• After opening a deep link, relevant content is visible without further action required; app provides the "first click free" experience even on a freshly installed app.

• App supports a deep link that opens the home screen.• App implements the App Indexing API to surface app's history in Google

app query autocompletions. (Optional)

Page 27: Android Deep Linking

www.letsnurture.com

Website and server• Deep link annotations have been added to

sitemaps or to web pages.

• None of the domains or subdomains the app needs resources from have robots.txt that blocks Googlebot from those resources.

• Official website(s) for your app have been verified in your app's Play Console.

Page 28: Android Deep Linking

www.letsnurture.com

Test your deep links• To test android-app:// URIs on your phone,

enter a deep link URI in the text box below. It will generate a QR code that can be scanned using a barcode scanner app on your Android phone (e.g. Barcode Scanner), which should open a browser page with a link. When you click on the link on your phone, it should open the deep link you have entered in the text box.