背景
我今天刚刚创建了一个新的 POC(关于活动转换,但这不是主题),我注意到在主要活动的“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"/>
问题
看着写的网站,我仍然不明白它是什么。
我想这是如何使用它,但我不明白它是如何工作的。
另外,奇怪的是我创建的任何其他新项目都没有显示这行新代码
问题
- 这是什么?它有什么作用?
- 我该怎么办?
- 是否有任何自定义?有什么建议吗?
- 在哪些情况下会生成这行代码?我没有注意到它是如何以及何时创建的......
根据我在网站上阅读和看到的内容,我的猜测是,这仅用于可以执行某种搜索的应用程序,以便 Google 可以向用户显示以前的查询和更快的结果。