Android Developers

Add URL and App Indexing
Support
Android Studio helps you add support for
URLs, app indexing, and search
functionality to your apps. These features
can help to drive more traf�c to your app,
discover which app content is used most,
make it easier for users to �nd content in
an installed app, and attract new users.

In this document
Typical Work�ow
Adding an Intent Filter for
URL Support and Google
Search
Adding App Indexing API
Skeleton Code to an Activity
Testing a URL

Typical Work�ow
To use Android Studio to add support for URL,
app indexing, and search features to your app:
1. Add intent �lters and code to handle

Viewing App Indexing API
Messages in the logcat
Monitor
Con�guring Lint
Performing a Google App
Indexing Test

incoming intents.
2. Associate a website with your app.
3. Add App Indexing API code.

See also
App Indexing

Intent �lters and the App Indexing API are

Making Your App Content
Searchable by Google

ways to implement URL support and app

Handling App Links

indexing, but there are other possible

Improving Your Code with lint

implementations as well. See Alternate

logcat Monitor

Android Indexing Methods

Google Search Console

(https://developers.google.com/app-indexing/reference

Google Play Services

/deeplinks)

for more information.

Intent �lters for URLs
Android Studio can create a basic intent �lter
in your manifest that you can customize to
de�ne URLs for your app. You can then write

Video
DevBytes: App Indexing

Dependencies and

0 (API level 23) and higher.com/training/app-links/index. The Android Lint tool has warnings for certain issues involving URL support and . features such as Now on Tap and enhanced search result display (like including your app icon) become available.Java code in an activity to handle the intent. you can optionally exclude app content from Google Search.1. you can associate your website with your app by using the Google Search Console and Google Play Developer Console. add the App Indexing API code to your app. After you associate a website with your app.google.html) instead.3 (API level 9) or higher Android Studio 1.com/app-indexing/reference/deeplinks#allow-access-by-googlebot-optional) can’t get content from your app. Chrome displaying google.5 or higher Google Play Services 8. URL support and App Indexing API testing Android Studio helps you test your code with the following features: URL support testing helps you verify that a speci�ed URL can launch an app. prerequisites This implementation lets users directly open the speci�ed app activity by clicking a URL. Users can see the URLs in google. In addition. Afterward.com in a browser. The logcat Monitor helps you test App Indexing API calls in an activity. Google Search app users must be signed in to see URLs in their search results.android.0 or higher Website association with URLs After setting up URL support for your app.com serves search results with URLs that are accessible to both signed-in users and those who aren't. in the Google Search app. and in Google Now on Tap. you can add default handlers and veri�cation for URLs (https://developer. As an alternative to associating your app with a website. App Indexing API code in activities Next. for Android 6. Android Studio can create skeleton code in an activity that you can then customize to support app indexing. Google indexes your app for URLs de�ned in your intent �lters and begins to include them in search results. The App Indexing API allows app indexing even if Googlebot (https://developers. Android 2.

Place your cursor in an activity. -->  <<ddaattaa      android:host="www.html) mechanisms.category. and then select Code > Generate > URL. The Code Editor adds an intent �lter similar to the following: <!-.ATTENTION: This data URL was auto-generated.intent. double-click the AndroidManifest.example.co/AppIndexing/AndroidStudio to publish your URLs.com/studio/projects/index.intent. In the Android view (https://developer.ATTENTION: This intent was auto-generated. A Google App Indexing test checks whether Google can index a URL by either crawling your app page or using the App Indexing API.    TODO: Change the host or pathPrefix as necessary. Click and select Add URL.jetbrains.VIEW" //>>                  <<ccaatteeggoorryy android:name="android.com/idea/help/intention-actions.BROWSABLE" //>>  <!-.xml �le to open it in the Code Editor.action. 2.DEFAULT" //>>  <<ccaatteeggoorryy android:name="android.html) and generate code (https://www.    We recommend that you use the HTTP scheme. --> <<iinntteenntt--ffiilltteerr>>    <<aaccttiioonn android:name="android. The details for implementing URL support and app indexing are described next. These warnings and errors appear in the Code Editor and in Lint inspection results. Right-click in an <activity> element and select Generate > URL. Adding an Intent Filter for URL Support and Google Search To use Android Studio features to add an intent �lter de�ning a URL: 1.com"      android:pathPrefix="/gizmos" . Follow instructions at  https://g.android.html#ProjectFiles) of the Project window.intent.the App Indexing API.com/idea/help/generating-code. The Code Editor adds skeleton code using the intention action (https://www. click in the left column so the light bulb appears. Insert an intent �lter in one of the following ways: In an <activity> element.jetbrains.category.

com/gizmos. for example. Also.com/training /app-indexing/deep-linking. 5.android. remember to include a URL for your app home screen so it’s included in search results.example.com/training/app-indexing/deeplinking. In addition. To test and debug your links. Optionally add App Indexing API code (#indexing) to support additional search features. 2.0 (API level 23) and higher.html). add link default handling and veri�cation (https://developer.google. Alternatively. De�ne an association (https://developers.com/app-indexing/android /app#create-the-noindexxml-�le) from the Google index. The URLs you specify in your intent �lters can be the same as the URLs of the comparable pages on your website. To support Google Search for your URLs: 1. 4.google.html#adding-�lters) and optionally the <category> element.       android:scheme="http" //>> <<//iinntteenntt--ffiilltteerr>> 3. as needed. add Java code (https://developer. you can preview your APK in the Google Search Console . Enable the following Android Lint categories (#lint): Missing support for Google App Indexing URL not supported by app for Google App Indexing Perform a Google App Indexing Test (#appindexingtest). Google will index any URLs starting with http://www.html#handling-intents) to read data from the intent �lter and direct the app to respond accordingly.com/training/app-links/index. In the previous sample code. 3. you can use the following Android Studio features: Launch your URL (#testintent) in Android Studio to test that it works. Modify the <data> element (https://developer. In the corresponding activity. Test your URL (#testintent). We recommend that you de�ne a <data> element that supports URLs that you’ll add in the future. Optionally exclude certain URLs (https://developers.com/app-indexing/android/app#declarea-website-association) between your app and your website.android. for Android 6.android.

or the onStop() method doesn’t contain an AppIndexApi. whether the app is associated with a website or not.android. make sure your cursor is within an activity.(https://developers.com/idea/help/intention-actions.start() or AppIndexApi. Adding App Indexing API Skeleton Code to an Activity After adding URL support to your app. Insert skeleton code in one of the following ways: In an activity de�nition. In Android view (https://developer.end() or AppIndexApi.jetbrains.html#ProjectFiles) in the Project window. If you don’t see the App Indexing API Code menu item. and select Insert App Indexing API Code. and check your code for App Indexing API methods.com/app-indexing/android/test#preview-your-apk-on-search-console) to test your URLs. 2. double-click the activity Java �le to open it in the Code Editor.view() call. click in the Java code so the light bulb Click appears. To add App Indexing API code to an activity: 1. or the onStart() method doesn’t contain an AppIndexApi.google. Place the cursor in an activity. Right-click in an activity de�nition and select Generate > App Indexing API Code.html) and generate code (https://www.viewEnd() call.html) mechanisms.com/idea/help/generating-code. The Code Editor adds skeleton code using the intention action (https://www. you can add App Indexing API code to an activity to support additional search features. and then select Code > Generate > App Indexing API Code. The activity doesn’t have an onStop() method.jetbrains. The Code Editor can insert skeleton Java code into an activity in the following circumstances: The activity doesn’t have an onStart() method. The Code Editor adds Java code similar to the following: /** .com/studio/projects/index.

BBuuiillddeerr(tthhiiss).   */  pprriivvaattee GGoooogglleeAAppiiCClliieenntt client.co/AppIndexing/AndroidStudio for more informat  client.example.AAppppIInnddeexxAAppii. // TODO: Define a title for the content sh          // TODO: If you have web page content that matches          // this app activity's content.connect().          // make sure this auto-generated web page URL is correc          // Otherwise. // TODO: choose an action type.    @Override    ppuubblliicc vvooiidd onStop() {        ssuuppeerr.          // TODO: Make sure this auto-generated app URL is corre          UUrrii.          UUrrii.example/http/www.onStart().onStop().com/gizmos").c  ). // TODO: choose an action type.com/gizmos").example.  AAppppIInnddeexx.example. set the URL to null.  AAppppIInnddeexx.              // ATTENTION: This was auto-generated to implement the App Inde      // See https://g.          UUrrii.parse("android-app://com.TYPE_VIEW.co/AppIndexing/AndroidStudio for more information.parse("http://www. set the URL to null.AAppppIInnddeexxAAppii. .          "Main Page". // TODO: Define a title for the content sh          // TODO: If you have web page content that matches          // this app activity's content.  client.TYPE_VIEW.newAction(          AAccttiioonn.          // TODO: Make sure this auto-generated app URL is corre          UUrrii.eenndd(client.co/AppIndexing/AndroidStudio for more informat      client = nneeww GGoooogglleeAAppiiCClliieenntt.addApi(AAppppIInnddeexx  }    @Override    ppuubblliicc vvooiidd onStart() {        ssuuppeerr. viewAction). viewAction).          * ATTENTION: This was auto-generated to implement the App Indexing   * See https://g.                                 }                                                              }  // ATTENTION: This was auto-generated to implement the App Inde  // See https://g.parse("http://www.example.                                                                                              }  // ATTENTION: This was auto-generated to implement the App Inde  // See https://g.start(client.newAction(          AAccttiioonn.disconnect().co/AppIndexing/AndroidStudio for more informat  AAccttiioonn viewAction = AAccttiioonn.          "Main Page".example/http/www.  AAccttiioonn viewAction = AAccttiioonn.parse("android-app://com.          // make sure this auto-generated web page URL is correc          // Otherwise.c  ).

you can use the following Android Studio features: Examine logcat Monitor Messages (#testindexing).For more information about the App Indexing API methods. In addition.com/android/guides/setup) .google. see Android API for App Indexing (https://developers. To launch a URL from Android Studio: . the Code Editor also modi�es your build. If your app already depends on it but the version is lower than 8.google.1.google. 3. your app is upgraded to version 8. Verify that your app indexing code is working (#testindexing) by using the logcat Monitor. Enable the following Android Lint category (#lint): Missing support for Google App Indexing API Perform a Google App Indexing Test (#appindexingtest).com/app-indexing/android/publish) .com/app-indexing/android/publish#add-google-play-services) and Setting Up Google Play Services (https://developers. For more information. If your app isn’t already con�gured for the Google Play Services App Indexing API.0. To test and debug your App Indexing API code.google. which help you �nd areas that need work. see the Action Class Constant Summary (https://developers.com/android/reference/com/google/android/gms/appindexing /Action#constant-summary) . Pay attention to the comments. such as setting the title and URLs. For information about the action types. see Add the App Indexing API (https://developers.com/app-indexing/reference/package-summary) . you can preview your APK in the Google Search Console (https://developers.google. you can specify a URL to launch so you can test it. see Add Google Play Services (https://developers. For more information and to correct any issues. 4.1. as needed.google.xml �les to include it. Customize the skeleton code.gradle and AndroidManifest. Testing a URL When you run your app from Android Studio.com/app-indexing/android/test#preview-your-apk-on-search-console) .0.

android. Select the General tab. 3. In Android Studio. for example. Select Run > Run app or Debug app. and displays the app at the speci�ed activity. 2. 7. see Build and Run Your App (https://developer. open your project in Android view (https://developer.com/gizmos.android. and click OK. The logcat Monitor is part of Android Monitor in Android Studio. Or type the URL you want to test. You can view App Indexing API log messages while the app is running. For example. select a connected device or an emulator. Viewing App Indexing API Messages in the logcat Monitor The logcat Monitor can display app indexing log messages to determine if your App Indexing API code is pushing the correct data to the cloud. select Run > Edit Con�gurations.com/studio /projects/index. For more information about creating run con�gurations at the project. Otherwise.com/tools/building/buildingstudio. the app launches in the device or emulator. 9. select the module you want to test. If the link is successful. To view App Indexing API messages in the logcat Monitor: 1.html#ProjectFiles). Click OK. 5. click … to select from a list of de�ned URLs. select URL. 8. . an error message appears in the Run window. and module levels. beneath Android Application. default. you can check the app title and the URL. 6. In the Launch �eld. http://example.1.html). as described next. In the Run/Debug Con�gurations dialog. If the Select Deployment Target dialog appears. After opening a project. 4. In the URL �eld. Run your app in Android Studio so it launches a URL (#testintent).

You can view URL and app indexing warnings and errors in two ways: As pop-up text in the Code Editor.com/tools/help/am-logcat. To set default Lint checks for URLs and the App Indexing API: 1. In the Lint Inspection Results window after you select Analyze > Inspect Code. Is the Google Play Services version on the device or emulator lower than the version speci�ed in the build. Set the log level (https://developer. 4. 5. Display Android Monitor (https://developer.2. select No Filters.html#searching) for the string "appindex". see the Google Play Services Download (https://play. it might be out-of-date and should be upgraded to a higher version.google.com/store/apps/details?id=com.android.com/android/guides/setup) .gms&hl=en) page and Setting Up Google Play Services (https://developers.com/tools/help/am-logcat.google.google.html#running) and click the logcat tab. In the �lter menu.html#level) to Verbose. If they don’t.android.android.android.gradle �le? If so. it highlights the problematic code in yellow.com/tools/help/am-logcat. Search the log (https://developer. check the following items: Is Google Play Services installed on the device or emulator? You can check the settings on the device. Visit app pages that trigger App Indexing API calls. In Android Studio. Con�guring Lint You can use the Android Studio built-in Lint tool to check whether you have valid URLs de�ned in the manifest and have implemented the App Indexing API correctly in activities. App indexing log messages should appear. 3.com/studio /projects/index.android. open your project in Android view (https://developer. . For more information. or underlines the code in red for more serious issues.html#ProjectFiles). 6. When Lint �nds a problem.

5.android. For example.html#ProjectFiles) and select a portion of your project that you want to test. the following Lint warning appears for the �rst setting: 6. If you want to change the Lint settings.Reports a warning if the app hasn’t implemented URLs. respectively. specify the Lint settings you . 4. select Editor > Inspections. Select Analyze > Inspect Code. 2. 3. This error setting is enabled by default. The scope speci�es the �les you want to analyze. Select File > Other Settings > Default Settings. select the inspection scope and pro�le. In the Default Preferences dialog. click …. 4.2. and the pro�le speci�es the Lint checks you’d like to perform.Reports if an app hasn’t implemented the App Indexing API at all. select Default or Project Default to set the scope for Android Studio or just for this project. In the Specify Inspection Scope dialog. To produce a list of Lint checks displayed in the Inspection Results window: 1. In the Inspections dialog. URL not supported by app for Google App Indexing . Missing support for Google App Indexing API . which are used by Google Search. This warning setting is disabled by default.com/studio /projects/index. Click OK. optionally click Manage to de�ne a new pro�le.Reports URL errors in manifest code. 3. In the Pro�le �eld. In Android Studio. Expand the Android Lint category and change the Lint settings as needed: Missing support for Google App Indexing . This warning setting is enabled by default. open your project in Android view (https://developer.

Performing a Google App Indexing Test You can use a Google App Indexing Test to check whether Google can index a URL by either crawling your app page or using the App Indexing API. It does change the settings for pro�les displayed in the Inspections dialog. The results appear in a new tab in the Code Editor. The results appear in the Inspection Results window. Add URL (#intent) and App Indexing API (#indexing) support to your app. The test can take a few minutes to complete. In the Inspections dialog. Log in if you see a message asking you to log into a Google Cloud Platform account. select a Module. 2. Android Studio builds the APK and starts the test. URL. and Language. however. 5. In the Google App Indexing Test dialog. select Tools > Android > Google App Indexing Test. . In the Google App Indexing Test dialog.want. While your project is open in Android Studio. 4. Google can index the URL if your app supports at least one of the following: Googlebot can open and crawl the page identi�ed by the URL. 3. and then click OK. Note that changing Lint settings for a pro�le in the Inspections dialog doesn’t change the default settings. Click OK. you can search for the string "app indexing" to �nd the URL and App Indexing API Lint checks. click OK. Your app sends the correct data by using the App Indexing API. To perform a Google App Indexing Test: 1. as described in the previous procedure. 5.

To �x this issue. Check the crawling but preview on the right to see whether the content displays identi�ed blocked correctly. 6. Warning: Google When calling the App Indexing API.If the app preview on the right shows the screen that corresponds to the URL you're testing. make sure the resources resources. it might not matter. If these using Googlebot resources aren't critical. Warning or Error Description Error: Google Your app can't be crawled by Googlebot or using the cannot index this App Indexing API. then Googlebot can �nd the URL. page using the App Indexing API because the title is empty. The following table lists common errors and warnings you might encounter. Correct any issues the test identi�es. so Google isn't able to index this app.txt (https://support. Warning: The App When calling the App Indexing API. aren't blocked by robots. . Warning: Google The app references other resources. and repeat the test as often as needed. page.google.com /webmasters/answer/6062608) . the URL speci�ed in URL you sent by the app must match the opened URL. using the App Indexing API doesn't match the URL opened. the title shouldn't be cannot index this empty. and some of them can index this page are blocked or temporarily unavailable.

. We cannot index this recommended adding App Indexing API support to your page using the App app. Indexing API.Warning: Google Your app isn’t using the App Indexing API.