首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >什么是新生成的代码“这是自动生成以实现应用程序索引API。”?

什么是新生成的代码“这是自动生成以实现应用程序索引API。”?
EN

Stack Overflow用户
提问于 2015-12-27 22:27:32
回答 3查看 12.3K关注 0票数 18

背景

我今天刚刚创建了一个新的POC (关于活动转换,但这不是主题),我注意到在main活动的"onCreate“方法中写了一行新行:

    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    mClient = 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.
        mClient.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "SinglePhotoViewer 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.user.transitionstest/http/host/path")
        );
        AppIndex.AppIndexApi.start(mClient, 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.
                "SinglePhotoViewer 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.user.transitionstest/http/host/path")
        );
        AppIndex.AppIndexApi.end(mClient, viewAction);
        mClient.disconnect();
    }

这是添加到清单中的:

<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
        App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

问题所在

看着写好的网站,我还是不明白它是什么。

我猜是如何使用它的,但我不明白它是如何工作的。

另外,奇怪的是,我创建的任何其他新项目都不会显示这行新代码

问题

  1. 这是什么?它做了什么?
  2. 我应该用它做什么?
  3. 对它有什么自定义吗?有什么建议吗?
  4. 在哪些情况下会生成这行代码?我没有注意到它是如何以及何时被创建的--

我的猜测是,根据我在网站上读到的和看到的,这只适用于可以执行某种搜索的应用程序,这样Google就可以向用户显示以前的查询和更快的结果。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34481370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档