본문 바로가기
User Guide

Add URL and App Indexing Support (19)

by 각종 잡상식 지식 모음 2016. 6. 2.
반응형

Add URL and App Indexing Support

안드로이드 Studio는 URL지원, app 색인 및 검색기능을 app에 추가하는 것을 도와줍니다.
이들 기능은 app에 보다 많은 트래픽을 유도하고, 어떤 app이 가장 많이 사용되는지 발견하고, 사용자가 설치된 app에서 콘텐츠를 쉽게 검색하도록 만들고, 새로운 사용자를 유치하는 것을 도와줍니다.

Android Studio helps you add support for URLs, 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 support for URL, app indexing, and search features to your app:

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

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

Intent filters for URLs

안드로이드 스튜디오는 앱의 URL을 사용자가 정의할 수 있는 기본 인텐트 필터를 manifest 안에 만들 수 있습니다.
그런 다음 intent를 처리하기 위한 activity안에 자바 코드를 작성할 수 있습니다.
이 구현으로 사용자는 URL을 직접 클릭하여 지정된 app activity을 열 수 있습니다.
사용자들은 브라우저로 google.com, Google Search app과 Google Now on Tap에서 URL을 볼 수 있습니다

Android Studio can create a basic intent filter in your manifest that you can customize to define 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 URL. Users can see the URLs in google.com in a browser, in the Google Search app, and in Google Now on Tap.

Website association with URLs

app의 URL 지원을 설정한 후, Google 검색 콘솔Google Play 개발자 콘솔을 사용하여 웹사이트를 app과 연계할 수 있습니다.
그 후, 구글은 intent 필터에 정의된 URL에 대한 app을 인덱스하며, 검색 결과에 app을 포함시키기 시작합니다.
또한 선택적으로 Google 검색에서 app 콘텐츠를 제외 할 수 있습니다.
app과 웹사이트를 연결하면, Now on Tap과 강화된 검색 결과 표시(app아이콘 포함)와 같은 기능을 사용할 수 있게 됩니다.
After setting up URL support 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.

app을 웹사이트와 연결하는 대신, 안드로이드 6.0 (API 레벨 23) 이상에서, 대신 URL에 대한 기본 핸들러 및 검증을 추가시킬 수 있습니다.
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 URLs instead.

google.com 표시 크롬은 signed-in한 사용자와 sign-in 하지 않은 사용자에게 접근가능한 URL 검색 결과를 제공합니다.
구글 검색 app 사용자는 검색 결과에서 URL을 보려면 sign-in 해야 합니다.

Chrome displaying google.com serves search results with URLs that are accessible to both signed-in users and those who aren't. Google Search app users must be signed in to see URLs 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 Googlebotcan’t get content from your app.

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 specified URL can launch an app.
  • The logcat Monitor helps you test App Indexing API calls in an activity.
  • The Android Lint tool has warnings for certain issues involving URL support and the App Indexing API. These warnings and errors appear in the Code Editor and in Lint inspection results.
  • A Google App Indexing test checks whether Google can index a URL by either crawling your app page or using the App Indexing API.

The details for implementing URL support and app indexing are described next.

Adding an Intent Filter for URL Support and Google Search


To use Android Studio features to add an intent filter defining a URL:

  1. In the Android view of the Project window, double-click the AndroidManifest.xml file to open it in the Code Editor.
  2. Insert an intent filter in one of the following ways:
    • In an <activity> element, click in the left column so the light bulb Lightbulb icon appears. Click Lightbulb icon and select Create URL.
    • Right-click in an <activity> element and select Generate > URL.
    • Place your cursor in an activity, and then select Code > Generate > URL.

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

    <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>
  3. Modify the <data> element and optionally the <category> element, as needed.
  4. 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 http://www.example.com/gizmos. Also, remember to include a URL for your app home screen so it’s included in search results.

    The URLs you specify in your intent filters can be the same as the URLs of the comparable pages on your website.

  5. In the corresponding activity, add Java code to read data from the intent filter and direct the app to respond accordingly.
  6. Test your URL.

To support Google Search for your URLs:

  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 certain URLs from the Google index.
  4. Optionally add App Indexing API code to support additional search features.

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 URLs, whether the app is associated with a website or not.

Adding App Indexing API Skeleton Code to an Activity


After adding URL support to your app, you can add App Indexing API code to an activity to support additional search features.

To add App Indexing API code to an activity:

  1. In Android view in the Project window, double-click the activity Java file to open it in the Code Editor.
  2. Insert skeleton code in one of the following ways:
    • In an activity definition, click in the Java code so the light bulb Lightbulb icon appears. Click Lightbulb icon and select Insert App Indexing API Code.
    • Right-click in an activity definition and select Generate > App Indexing API Code.
    • Place the cursor in an activity, and then select Code > Generate > 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:

    • The activity doesn’t have an onStart() method, or the onStart() method doesn’t contain an AppIndexApi.start() or AppIndexApi.view() call.
    • The activity doesn’t have an 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://www.example.com/gizmos"),
                   
    // TODO: Make sure this auto-generated app URL is correct.
                   
    Uri.parse("android-app://com.example/http/www.example.com/gizmos")
           
    );
           
    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://www.example.com/gizmos"),
                   
    // TODO: Make sure this auto-generated app URL is correct.
                   
    Uri.parse("android-app://com.example/http/www.example.com/gizmos")
           
    );
           
    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 theAction 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 andAndroidManifest.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.

  3. Customize the skeleton code, as needed.
  4. 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.

  5. Verify that your app indexing code is working by using the logcat Monitor.

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 URL


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

To launch a URL from Android Studio:

  1. In Android Studio, open your project in Android view.
  2. After opening a project, select Run > Edit Configurations.
  3. In the Run/Debug Configurations dialog, beneath Android Application, select the module you want to test.
  4. Select the General tab.
  5. In the Launch field, select URL.
  6. In the URL field, click  to select from a list of defined URLs.
  7. Or type the URL you want to test, for example, http://example.com/gizmos.

  8. Click OK.
  9. Select Run > Run app or Debug app.
  10. If the Select Deployment Target dialog appears, select a connected device or an emulator, and click OK.
  11. 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 Build and Run Your App.

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.

To view App Indexing API messages in the logcat Monitor:

  1. Run your app in Android Studio so it launches a URL.
  2. Display Android Monitor and click the logcat tab.
  3. Set the log level to Verbose.
  4. In the filter menu, select No Filters.
  5. Search the log for the string "appindex".
  6. App indexing log messages should appear. If they don’t, check the following items:

    • Is Google Play Services installed on the device or emulator? You can check the settings on the device.
    • Is the Google Play Services version on the device or emulator lower than the version specified in the 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.

  7. Visit app pages that trigger App Indexing API calls.

Configuring Lint


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

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

  • As pop-up text in the Code Editor. When Lint finds a problem, it highlights the problematic code in yellow, or underlines the code in red for more serious issues.
  • In the Lint Inspection Results window after you select Analyze > Inspect Code.

To set default Lint checks for URLs and the App Indexing API:

  1. In Android Studio, open your project in Android view.
  2. Select File > Other Settings > Default Settings.
  3. In the Default Preferences dialog, select Editor > Inspections.
  4. In the Profile field, select Default or Project Default to set the scope for Android Studio or just for this project, respectively.
  5. Expand the Android Lint category and change the Lint settings as needed:
    • Missing support for Google App Indexing - Reports a warning if the app hasn’t implemented URLs, which are used by Google Search. This warning setting is enabled by default.
    • Missing support for Google App Indexing API - Reports if an app hasn’t implemented the App Indexing API at all. This warning setting is disabled by default.
    • URL not supported by app for Google App Indexing - Reports URL errors in manifest code. This error setting is enabled by default.

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

    Lint warning

  6. Click OK.

To produce a list of Lint checks displayed in the Inspection Results window:

  1. In Android Studio, open your project in Android view and select a portion of your project that you want to test.
  2. Select Analyze > Inspect Code.
  3. In the Specify Inspection Scope dialog, select the inspection scope and profile.
  4. The scope specifies the files you want to analyze, and the profile specifies the Lint checks you’d like to perform.

  5. 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.
  6. In the Inspections dialog, you can search for the string "app indexing" to find the URL 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.

  7. Click OK.
  8. The results appear in the Inspection Results window.

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. Google can index the URL if your app supports at least one of the following:

  • Googlebot can open and crawl the page identified by the URL.
  • Your app sends the correct data by using the App Indexing API.

To perform a Google App Indexing Test:

  1. Add URL and App Indexing API support to your app.
  2. While your project is open in Android Studio, select Tools > Android > Google App Indexing Test.
  3. In the Google App Indexing Test dialog, select a ModuleURL, and Language.
  4. Log in if you see a message asking you to log into a Google Cloud Platform account.
  5. In the Google App Indexing Test dialog, click OK.
  6. Android Studio builds the APK and starts the test. The test can take a few minutes to complete. The results appear in a new tab in the Code Editor.

    Google App Indexing Test results

    If the app preview on the right shows the screen that corresponds to the URL you're testing, then Googlebot can find the URL.

  7. Correct any issues the test identifies, and repeat the test as often as needed.

The following table lists common errors and warnings you might encounter.

Warning or ErrorDescription
Error: Google cannot index this page.Your app can't be crawled by Googlebot or using the App Indexing API, so Google isn't able to index this app.
Warning: The App URL you sent by using the App Indexing API doesn't match the URL opened.When calling the App Indexing API, the URL specified in the app must match the opened URL.
Warning: Google cannot index this page using the App Indexing API because the title is empty.When calling the App Indexing API, the title shouldn't be empty.
Warning: Google can index this page using Googlebot crawling but identified blocked resources.The app references other resources, and some of them are blocked or temporarily unavailable. If these resources aren't critical, it might not matter. Check the preview on the right to see whether the content displays correctly. To fix this issue, make sure the resources aren't blocked by robots.txt.
Warning: Google cannot index this page using the App Indexing API.Your app isn’t using the App Indexing API. We recommended adding App Indexing API support to your app.


반응형

댓글