diff --git a/docs/html/images/tools/ai-ilightbulb.png b/docs/html/images/tools/ai-ilightbulb.png new file mode 100644 index 0000000000000..e9522f323e210 Binary files /dev/null and b/docs/html/images/tools/ai-ilightbulb.png differ diff --git a/docs/html/images/tools/ai-lint.png b/docs/html/images/tools/ai-lint.png new file mode 100644 index 0000000000000..2a0aabc8f1a36 Binary files /dev/null and b/docs/html/images/tools/ai-lint.png differ diff --git a/docs/html/tools/building/building-studio.jd b/docs/html/tools/building/building-studio.jd index 4431194120905..ef6e94bcfb23f 100644 --- a/docs/html/tools/building/building-studio.jd +++ b/docs/html/tools/building/building-studio.jd @@ -32,6 +32,7 @@ parent.link=index.html Using the Android Emulator
  • Signing Your Applications
  • +
  • Deep Link and App Indexing API Support in Android Studio
  • diff --git a/docs/html/tools/help/app-link-indexing.jd b/docs/html/tools/help/app-link-indexing.jd new file mode 100644 index 0000000000000..611373a28ab5e --- /dev/null +++ b/docs/html/tools/help/app-link-indexing.jd @@ -0,0 +1,514 @@ +page.title=Deep Link and App Indexing API Support in Android Studio +parent.title=Tools +parent.link=index.html +page.tags=app indexing +@jd:body + +
    +
    +

    In this document

    +
      +
    1. Typical Workflow
    2. +
    3. Adding an Intent Filter for Deep Linking and Google Search
    4. +
    5. Adding App Indexing API Skeleton Code to an Activity
    6. +
    7. Testing a Deep Link
    8. +
    9. Viewing App Indexing API Messages in the logcat Monitor
    10. +
    11. Configuring Lint
    12. +
    + +

    See also

    +
      +
    1. App Indexing
    2. +
    3. Making Your App Content Searchable by Google
    4. +
    5. Handling App Links
    6. +
    7. Improving Your Code with lint
    8. +
    9. logcat Monitor
    10. +
    11. Google Search Console
    12. +
    13. Google Play Services
    14. +
    + +

    Video

    +
      +
    1. DevBytes: App Indexing
    2. +
    + +

    Dependencies and prerequisites

    + + +
    +
    + +

    Android Studio helps you add deep links, app indexing, and search functionality to your apps. + These features can help to drive more traffic to your + app, discover which app content is used most, make it easier for users to find content in an + installed app, and attract new users.

    + +

    Typical Workflow

    + +

    To use Android Studio to add deep link, app indexing, and search features to your app, follow + these basic steps:

    + +
      +
    1. Add intent filters and code to handle incoming intents.
    2. +
    3. Associate a website with your app.
    4. +
    5. Add App Indexing API code.
    6. +
    + +

    Intent filters and the App Indexing API are ways to implement deep links and app indexing, but + there are other possible implementations as well. See + Alternate Android Indexing Methods + for more information.

    + +

    Intent filters for deep links

    + +

    Android Studio can create a basic intent filter in your manifest that you can customize to + define deep link URLs for your app. You can then write Java code in an activity to handle the + intent. This implementation lets users directly open the specified app activity by + clicking a deep link. Users can see the deep links in google.com in a browser, in the + Google Search app, and in Google Now on Tap.

    + +

    Website association with deep links

    + +

    After setting up deep links for your app, you can associate your website with your app by using + the Google Search Console and Google Play Developer Console. Afterward, Google indexes your app + for URLs defined in + your intent filters and begins to include them in search results. In addition, you can optionally + exclude app content from Google Search. After you associate a website with your app, features + such as Now on Tap and enhanced search result display (like including your app icon) + become available.

    + +

    As an alternative to associating your app with a website, + for Android 6.0 (API level 23) and higher, you can add + default handlers and verification for deep links + instead.

    + +

    Chrome displaying google.com serves search results with deep links that are accessible to both + signed-in users and those who aren't. Google Search app users must be signed in to see deep links + in their search results.

    + +

    App Indexing API code in activities

    + +

    Next, if you want to support additional search features, such as autocompletions, you can + add App Indexing API code to your app. Android Studio can create skeleton code in an activity + that you can then customize to support app indexing. The App Indexing API allows app indexing + even if + Googlebot + can’t get content from your app.

    + +

    Deep link and App Indexing API testing

    + +

    Android Studio helps you test your code with the following features:

    + + + +

    The details for implementing deep links and app indexing are described next. + + +

    Adding an Intent Filter for Deep Linking and Google Search

    + +

    To use Android Studio features to add an intent filter defining a deep link, follow these + steps:

    + +
      +
    1. In the Android view + of the Project window, double-click the AndroidManifest.xml file to open it + in the Code Editor.
    2. +
    3. Insert an intent filter in one of the following ways:
    4. + + +

      The Code Editor adds skeleton code using the + intention action and + generate code mechanisms.

      + +

      The Code Editor adds an intent filter similar to the following:

      +
      +<!-- ATTENTION: This intent was auto-generated. Follow instructions at
      + https://g.co/AppIndexing/AndroidStudio to publish your Android app deep links. -->
      +<intent-filter>
      +   <action android:name="android.intent.action.VIEW" />
      +
      +   <category android:name="android.intent.category.DEFAULT" />
      +   <category android:name="android.intent.category.BROWSABLE" />
      +   <!-- ATTENTION: This data URL was auto-generated.
      +     We recommend that you use the HTTP scheme.
      +     TODO: Change the host or pathPrefix as necessary. -->
      +   <data
      +       android:host="www.example.com"
      +       android:pathPrefix="/gizmos"
      +       android:scheme="http" />
      +</intent-filter>
      +
      + +
    5. Modify the + <data> element + and optionally the <category> element, as needed.
    6. + + +

      We recommend that you define a <data> element that supports URLs that you’ll + add in the future. In the previous sample code, for example, Google will index any URLs starting + with www.example.com/gizmos. Also, remember to + include a deep link for your app home screen so it’s included in search results.

      + +

      Deep link URLs can be the same as the URLs of the comparable pages on your website.

      + +
    7. In the corresponding activity, + add Java code + to read data from the intent filter and direct the app to respond accordingly.
    8. +
    9. Test your deep link.
    10. + +
    + +

    To support Google Search for your deep links, follow these steps:

    +
      +
    1. Define an association + between your app and your website.
    2. +

      Alternatively, for Android 6.0 (API level 23) and higher, add + link default handling and verification.

      +
    3. Optionally + exclude app URLs + from the Google index.
    4. +
    5. Optionally add App Indexing API code to support additional search + features.
    6. +
    + + +

    To test and debug your links, you can use the following Android Studio features:

    + + +

    In addition, you can + preview your APK in the Google Search Console + to test your deep links, whether the app is associated with a website or not.

    + + + +

    Adding App Indexing API Skeleton Code to an Activity

    + +

    After adding deep links, you can add App Indexing API code to an activity to support additional + search features.

    + +

    To add App Indexing API code to an activity, follow these steps:

    +
      +
    1. In Android view + in the Project window, double-click the activity Java file to open it in the + Code Editor.
    2. +
    3. Insert skeleton code in one of the following ways:
    4. + + + +

      The Code Editor adds skeleton code using the + intention action and + generate code + mechanisms.

      + +

      If you don’t see the App Indexing API Code menu item, make sure your cursor is + within an activity, and check your code for App Indexing API methods. The Code Editor can insert + skeleton Java code into an activity in the following circumstances:

      + + + + +

      The Code Editor adds Java code similar to the following:

      +
      +   /**
      +    * ATTENTION: This was auto-generated to implement the App Indexing API.
      +    * See https://g.co/AppIndexing/AndroidStudio for more information.
      +    */
      +   private GoogleApiClient client;
      +
      +       // ATTENTION: This was auto-generated to implement the App Indexing API.
      +       // See https://g.co/AppIndexing/AndroidStudio for more information.
      +       client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
      +   }
      +
      +
      +   @Override
      +   public void onStart() {
      +       super.onStart();
      +
      +       // ATTENTION: This was auto-generated to implement the App Indexing API.
      +       // See https://g.co/AppIndexing/AndroidStudio for more information.
      +       client.connect();
      +       Action viewAction = Action.newAction(
      +               Action.TYPE_VIEW, // TODO: choose an action type.
      +               "Main Page", // TODO: Define a title for the content shown.
      +               // TODO: If you have web page content that matches
      +               // this app activity's content,
      +               // make sure this auto-generated web page URL is correct.
      +               // Otherwise, set the URL to null.
      +               Uri.parse("http://host/path"),
      +               // TODO: Make sure this auto-generated app deep link URI is correct.
      +               Uri.parse("android-app://com.example/http/host/path")
      +       );
      +       AppIndex.AppIndexApi.start(client, viewAction);
      +   }
      +
      +   @Override
      +   public void onStop() {
      +       super.onStop();
      +
      +       // ATTENTION: This was auto-generated to implement the App Indexing API.
      +       // See https://g.co/AppIndexing/AndroidStudio for more information.
      +       Action viewAction = Action.newAction(
      +               Action.TYPE_VIEW, // TODO: choose an action type.
      +               "Main Page", // TODO: Define a title for the content shown.
      +               // TODO: If you have web page content that matches
      +               // this app activity's content,
      +               // make sure this auto-generated web page URL is correct.
      +               // Otherwise, set the URL to null.
      +               Uri.parse("http://host/path"),
      +               // TODO: Make sure this auto-generated app deep link URI is correct.
      +               Uri.parse("android-app://com.example/http/host/path")
      +       );
      +       AppIndex.AppIndexApi.end(client, viewAction);
      +       client.disconnect();
      +   }
      +}
      +
      + +

      For more information about the App Indexing API methods, see + Android API for App Indexing. + For information about the action types, see the + Action Class Constant Summary. +

      + +

      If your app isn’t already configured for the Google Play Services App Indexing API, the Code + Editor also modifies your build.gradle and AndroidManifest.xml files + to include it. If your app already depends on it but the version is lower than 8.1.0, your app + is upgraded to version 8.1.0. For more information and to correct any issues, see + Add Google Play Services + and Setting Up Google Play Services. +

      + +
    5. Customize the skeleton code, as needed.
    6. + +

      Pay attention to the comments, which help you find areas that need work, such as setting the + title and URLs. For more information, see + Add the App Indexing API. +

      +
    7. Verify that your app indexing code is working by using + the logcat Monitor.
    8. +
    + + + +

    To test and debug your App Indexing API code, you can use the following Android Studio + features:

    + + +

    In addition, you can + preview your APK in the Google Search Console.

    + + +

    Testing a Deep Link

    + +

    When you run your app from Android Studio, you can specify a deep link to launch so you can + test it.

    + +

    To launch a deep link from Android Studio, follow these steps:

    +
      +
    1. In Android Studio, open your project in + Android view.
    2. +
    3. After opening a project, select Run > Edit Configurations. +
    4. +
    5. In the Run/Debug Configurations dialog, beneath Android Application, + select the module you want to test.
    6. +
    7. Select the General tab.
    8. +
    9. In the Launch field, select Deep Link.
    10. +
    11. In the Deep Link field, click … to select from a list of + defined deep links.
    12. + +

      Or type the URL you want to test, for example, http://example.com/gizmos.

      +
    13. Click OK.
    14. +
    15. Select Run > Run app or Debug app.
    16. +
    17. If the Device Chooser dialog appears, select a connected device or an + emulator, and click OK.
    18. + +

      If the link is successful, the app launches in the device or emulator, and displays the app at + the specified activity. Otherwise, an error message appears in the Run window.

      +
    + +

    For more information about creating run configurations at the project, default, and module + levels, see + Building and Running from Android Studio. +

    + +

    You can view App Indexing API log messages while the app is running, as described next.

    + + +

    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. For example, you can check the app title and the + URL. The logcat Monitor is part of Android Monitor in Android Studio.

    + +

    Follow these steps:

    +
      +
    1. Run your app in Android Studio so it launches a deep link.
    2. +
    3. Display Android Monitor + and click the logcat tab.
    4. +
    5. Set the log level to + Verbose.
    6. +
    7. In the filter menu, select No Filters.
    8. +
    9. Search the log for the string + "appindex".
    10. + +

      App indexing log messages should appear. If they don’t, check the following items:

      + + +

      For more information, see the + Google Play Services Download + page and Setting Up Google Play Services. +

      +
    11. Visit app pages that trigger App Indexing API calls.
    12. +
    + + +

    Configuring Lint

    + +

    You can use the Android Studio built-in Lint tool to check whether you have valid deep links + defined in the manifest and have implemented the App Indexing API correctly in activities.

    + +

    You can view deep link and app indexing warnings and errors in two ways:

    + + + + +

    To set default Lint checks for deep links and the App Indexing API, follow these steps:

    +
      +
    1. In Android Studio, open your project in + Android view. +
    2. +
    3. Select File > Other Settings > + Default Settings.
    4. +
    5. In the Default Preferences dialog, select Editor > + Inspections.
    6. +
    7. In the Profile field, select Default or + Project Default to set the scope for Android Studio or just for this project, + respectively.
    8. +
    9. Expand the Android Lint category and change the Lint settings as needed:
    10. + + +

      For example, the following Lint warning appears for the first setting:

      +

      + +
    11. Click OK.
    12. +
    + + + +

    To produce a list of Lint checks displayed in the Inspection Results window, + follow these steps:

    +
      +
    1. In Android Studio, open your project in + Android view + and select a portion of your project that you want to test.
    2. +
    3. Select Analyze > Inspect Code.
    4. +
    5. In the Specify Inspection Scope dialog, select the inspection scope and profile.
    6. + +

      The scope specifies the files you want to analyze, and the profile specifies the Lint checks + you’d like to perform.

      +
    7. If you want to change the Lint settings, click …. In the Inspections + dialog, optionally click Manage to define a new profile, specify the Lint + settings you want, and then click OK.
    8. +

      In the Inspections dialog, you can search for the string "app indexing" +to find the deep link and App Indexing API Lint checks. Note that changing Lint settings for a +profile in the Inspections dialog doesn’t change the default settings, as described in +the previous procedure. It does change the settings for profiles displayed in the +Inspections dialog, however.

      +
    9. Click OK.
    10. +

      The results appear in the Inspection Results window.

      + +
    diff --git a/docs/html/tools/help/index.jd b/docs/html/tools/help/index.jd index a97a5516c3e57..e7b9111191970 100755 --- a/docs/html/tools/help/index.jd +++ b/docs/html/tools/help/index.jd @@ -43,6 +43,11 @@ avd) the emulator (emulator), and the Dalvik Debug Monitor S
    android
    Lets you manage AVDs, projects, and the installed components of the SDK.
    +
    Deep Link and App Indexing API Support
    +
    Helps you add deep links, app indexing, and search functionality to your apps. + These features can make it easier to find content in an installed app, drive more traffic to your + app, discover which app content is used most, and attract new users.
    +
    Hierarchy Viewer (hierarchyviewer)
    Provides a visual representation of the layout's View hierarchy with performance information for each node in the layout, and a magnified view of the display to closely examine the @@ -139,7 +144,7 @@ content is allowed.
    Image Asset Studio
    Helps you to generate custom icons for your Android applications from existing images, cliparts, or text. - It generates a set of icons at the appropriate resolution for each generalized screen density that your app + It generates a set of icons at the appropriate resolution for each generalized screen density that your app supports.
    Vector Asset Studio
    diff --git a/docs/html/tools/tools_toc.cs b/docs/html/tools/tools_toc.cs index 04ed7057ede35..14af176a470a0 100644 --- a/docs/html/tools/tools_toc.cs +++ b/docs/html/tools/tools_toc.cs @@ -146,8 +146,9 @@ class="en">Tools Help
  • AVD Manager
  • bmgr -
  • Device Monitor
  • +
  • Deep Link and App Indexing API Support
  • Desktop Head Unit
  • +
  • Device Monitor
  • dmtracedump
  • Draw 9-Patch
  • Emulator
  • diff --git a/docs/html/training/app-indexing/index.jd b/docs/html/training/app-indexing/index.jd index 15a6367289fd0..a1a47e96844f4 100644 --- a/docs/html/training/app-indexing/index.jd +++ b/docs/html/training/app-indexing/index.jd @@ -22,6 +22,7 @@ startpage=true target="_blank">App Indexing for Google Search
  • Intents and Intent Filters
  • +
  • Deep Link and App Indexing API Support in Android Studio
  • diff --git a/docs/html/training/app-links/index.jd b/docs/html/training/app-links/index.jd index 7ce95e646df36..27b6480287936 100644 --- a/docs/html/training/app-links/index.jd +++ b/docs/html/training/app-links/index.jd @@ -14,6 +14,10 @@ page.tags=androidm,marshmallow
  • Declare Website Associations
  • Test App Links
  • +

    See also

    +
      +
    1. Deep Link and App Indexing API Support in Android Studio
    2. +