App Indexing To Connect Your Android App

Google announced that they can now index the content within Android apps. The mechanism for doing so, they call, is app indexing.

App indexing allows webmasters to connect pages from your web sites with specific content within your Android app. This enables Android smartphone users who have your app installed to open it directly from relevant mobile search results on Google. Here is a picture of it in action:

appindexing1

For example, a webmaster who has a recipe website and an Android app can benefit from this. 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.

This currently works on the Google Search App version 2.8+ for Android 4.1+, and in mobile browsers on Android if the user is signed in. Plus, Google is only testing this with a select number of publishers. If you want to be included in this test, fill out this form.

To enable Google Search app indexing, you need to provide Google with information about the relationship between your app and web site. This process involves the following steps:

1.) Enable deep linking to specific content in your app by adding intent filters in your app manifest.
2.) Annotate these links in the associated web pages on your web site or in a Sitemap file.
3.) Opt in to allow Googlebot to crawl through your APK in the Google Play store to index your app content. You are automatically opted-in when you join as a participant in the early adopter program.

You can check out the video below to get more on app indexing

In this tutorial I will explain how to enable deep linking and indexing of your application content so that users can open this content directly from mobile search results.

Enabling Deep Links for App Content

To enable Google to crawl your app content and allow users to enter your app from search results, you must add intent filters for the relevant activities in your app manifest. These intent filters allow deep linking to the content in any of your activities. For example, the user might click on a deep link to view a page within a shopping app that describes a product offering that the user is searching for.

The following XML snippet shows how you might specify an intent filter in your manifest for deep linking. The URIs “example://gizmos” and “http://www.example.com/gizmos” both resolve to this activity.

 

<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 "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with "example://gizmos”
<data android:scheme="example"
android:host="gizmos" />
-->
</intent-filter>
</activity>

 

 

Once you’ve added intent filters with URIs for activity content to your app manifest, Android is able to route any Intent that has matching URIs to your app at runtime.

Read Data from Incoming Intents

Once the system starts your activity through an intent filter, you can use data provided by the Intent to determine what you need to render. Call the getData() and getAction() methods to retrieve the data and action associated with the incoming Intent. You can call these methods at any time during the lifecycle of the activity, but you should generally do so during early callbacks such as onCreate() or onStart().

Here’s a snippet that shows how to retrieve data from an Intent:

 

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}

 

Test Your Deep Links

You can use the Android Debug Bridge with the activity manager (am) tool to test that the intent filter URIs you specified for deep linking resolve to the correct app activity. You can run the adb command against a device or an emulator.

The general syntax for testing an intent filter URI with adb is:

 

$ adb shell am start
-W -a android.intent.action.VIEW
-d <URI> <PACKAGE>
[/code]

For example, the command below tries to view a target app activity that is associated with the specified URI.


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

 

 

The code above is linked to the code from developer.android.com

Leave a Comment: