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
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.
+ +To use Android Studio to add deep link, app indexing, and search features to your app, follow + these basic steps:
+ +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.
+ +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.
+ +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.
+ +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.
+ +Android Studio helps you test your code with the following features:
+ +The details for implementing deep links and app indexing are described next. + + +
To use Android Studio features to add an intent filter defining a deep link, follow these + steps:
+ +AndroidManifest.xml file to open it
+ in the Code Editor.<activity> element, click in the left column so the light bulb
+
appears. Click
+
+ and select Create Deep Link.<activity> element and select Generate
+ > Deep Link.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> ++ +
<data> element
+ and optionally the <category> element, as needed.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.
+ +To support Google Search for your deep links, follow these steps:
+Alternatively, for Android 6.0 (API level 23) and higher, add + link default handling and verification.
+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.
+ + + +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:
+
appears.
+ Click
+ and select Insert App Indexing API Code.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:
+ +onStart() method, or the onStart()
+ method doesn’t contain an AppIndexApi.start() or AppIndexApi.view()
+ call.onStop() method, or the onStop()
+ method doesn’t contain an AppIndexApi.end() or AppIndexApi.viewEnd()
+ call.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.
+
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. +
+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.
+ + +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:
+Or type the URL you want to test, for example, http://example.com/gizmos.
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.
+ + +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:
+App indexing log messages should appear. If they don’t, check the following items:
+build.gradle file? If so, it might be out-of-date and should be upgraded to
+ a higher version. For more information, see the + Google Play Services Download + page and Setting Up Google Play Services. +
+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:
+For example, the following Lint warning appears for the first setting:
+
To produce a list of Lint checks displayed in the Inspection Results window, + follow these steps:
+The scope specifies the files you want to analyze, and the profile specifies the Lint checks + you’d like to perform.
+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.
+The results appear in the Inspection Results window.
+ +emulator), and the Dalvik Debug Monitor S