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:
  1. In your Android manifest file, add one or more <intent-filter> elements for the activities that should be launchable from Google search results.
  2. Add an <action> tag that specifies the ACTION_VIEW intent action.
  3. 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.
  4. 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.
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:
<activity android:name="com.example.android.TestActivity"
           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>
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:
<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>
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"


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.

Here we can open any activity depends on our own requirement.
In app launcher activity

Uri data=getIntent().getData();

            if (data==null) 
            {
              
            }
            else
             {
              String response =getIntent().getData().toString();

             }
    from response we can get all URL related information

In twitter app manifest file we need configure below permissions

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="www.twitter.com"
                    android:pathPattern=".*"
                    android:scheme="http" />
 </intent-filter>

above  inside data tag having host,pathpattern,scheme
           
  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:
<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>

Link rel=alternate elements in XML Sitemaps

You can also annotate the relationship between a page and how to open it in your app using <link> elements in your website's XML Sitemap. For example:
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
 xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
  <loc>http://example.com/gizmos</loc>
  <xhtml:link rel="alternate" href="android-app://com.example.android/example/gizmos" />
</url>
...
</urlset>



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: /

No comments:

Post a Comment