android-Making Your App Content Searchable by Google,Specifying App Content for Indexing

desaco發表於2016-01-31

 As mobile apps become more pervasive, users are looking for relevant information not only from web sites but also from apps they have installed. You can enable Google to crawl through your app content and present your Android app as a destination to users through Google Search results, when that content corresponds to a web page that you own.

 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.
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.

 > 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>
 Note: Intent filters may only contain a single data element for a URI pattern. Create separate intent filters to capture additional URI patterns.

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

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

Follow these best practices to improve the user's experience:

  • The deep link should take users directly to the content, without any prompts, interstitial pages, or logins. Make sure that users can see the app content even if they never previously opened the application. It is okay to prompt users on subsequent interactions or when they open the app from the Launcher. This is the same principle as the first click free experience for web sites.
  • Follow the design guidance described in Navigation with Back and Up so that your app matches users' expectations for backward navigation after they enter your app through a deep link.
>> Specifying App Content for Indexing

  Google's web crawling bot (Googlebot), which crawls and indexes web sites for the Google search engine, can also index content in your Android app. By opting in, you can allow Googlebot to crawl the content in the APK through the Google Play Store to index the app content. To indicate which app content you’d like Google to index, simply add link elements either to your existingSitemap file or in the <head> element of each web page in your site, in the same way as you would for web pages.

 > The components that make up the URI format are:

  • package_name. Represents the package name for your APK as listed in the Google Play Developer Console.
  • scheme. The URI scheme that matches your intent filter.
  • host_path. Identifies the specific content within your application.
   For example, the following XML snippet shows how you might specify a link to your web page by using the<loc> tag, and a corresponding deep link to your Android app by using the <xhtml:link> tag.
<?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>example://gizmos</loc>
            <xhtml:link
                rel="alternate"
                href="android-app://com.example.android/example/gizmos" />
    </url>
    ...
</urlset>

 >Typically, you control how Googlebot crawls publicly accessible URLs on your site by using a robots.txt file. When Googlebot indexes your app content, your app might make HTTP requests as part of its normal operations. However, these requests will appear to your servers as originating from Googlebot. Therefore, you must configure your server's robots.txt file properly to allow these requests.

For example, the following robots.txt directive shows how you might allow access to a specific directory in your web site (for example, /api/) that your app needs to access, while restricting Googlebot's access to other parts of your site.

User-Agent: Googlebot
Allow: /api/
Disallow: /

To learn more about how to modify robots.txt to control web crawling, see the Controlling Crawling and Indexing Getting Started guide.

相關文章