This blog i started for sharing information for android developers.I just love to share my knowledge in my spare time and would appreciate any questions or feedback.

Thursday, May 1, 2014

Google Android App Indexing and deep Linking

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.

Add deep linking to your app

In order for Google to index the content in your app (and for users to enter your app from
Google search results), you must specify intent filters
in your app manifest that define how to reach specific content inside your app.
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.

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.

For example, the following activity allows users to enter the app using an intent to view information
about gizmos. The intent filter declares that the activity responds to
VIEW
action intents containing URIs that begin with http://example.com/Test:

The intent filter's <data>
element must provide the android:scheme attribute,
at a minimum. You can then add additional attributes to further refine the type of URI that
the activity accepts. For example, you might have multiple activities that accept similar URIs,
but which differ simply based on the path name, in which case you should add the
path, pathPattern, or pathPrefix attribute
to differentiate which activity the system should open for different URI paths.
The above example demonstrates a URI format that's intended to match web page URLs such that
the user can open your native app instead of the web page when clicking such links. If you want
a simplified format for the Android URIs, you can create alternative data URI formats such as
example://gizmos. For example, here's the same intent filter from above that includes support for
both the http://example.com/gizmos and example://gizmos format:

Both "example://gizmos" and "http://example.com/gizmos" URIs will resolve
to this activity. You can test this using the Android Debug Bridge:

adb shell am start "example://gizmos"

Important: When opening an app via a deep link, the app should provide users with a
First Click Free
experience. App deep links should take users directly to the content
without any prompts, interstitial pages, splash screens, login screens, etc., interrupting the content from being shown.
If the user takes any subsequent action, you can then prompt the user for an action, but app
indexing requires that the first click be free.

Example:

if suppose user click on https://twitter.com/BeingSalmanKhan first Android OS will check whether that twiiter application is installed on device or not .if it is installed so directly it open twitter app.

host="webservice url which is required to download data "
the main URL and webservice url both should be same

pathPattern=".*" means it allows all parameters

scheme ="protocal"

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 two equivalent ways to tell Google about the relationship between a web page and a deep link
into your app; these are:

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.

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.

Let's take an example: We're interested in annotating how the content hosted on
http://example.com/gizmos can be opened in the Android app that has the package ID com.example.android.

Link rel=alternate elements in HTML

In the HTML of the page http://example.com/gizmos, you add a
<link> element as follows for the deep link
http://example.com/gizmos:

Not all website URLs in a sitemap need to have a corresponding app deep link. Do not include
app deep links that aren't supported by your app.

If you are a news site and use News Sitemaps,
be sure to include your deep link annotations in the news sitemaps, as well as your general sitemaps.

Don't provide annotations for deep links that execute native ARM code. This enables app indexing to work for all platforms.

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: