根据官方文档,我已将深度链接作为应用程序索引的一部分。我在搜索自动完成部分面临一些不同但相关的问题:
- 自动完成结果仅显示最后打开的项目(以前访问的项目似乎被覆盖)。例如,假设在我的应用程序的趋势主题/集合列表视图中,用户打开项目 A(所附屏幕截图中的“shortvideos1”),恢复提要,然后打开项目 B(“shortvideos2”)。部分搜索“shortvid”仅显示后者:“shortvideos2”。完全搜索“shortvideos1”一无所获。建议仅在搜索结果列表中显示最新的项目。
- 结果列表中缺少某些内容访问。我有一个视图寻呼机,它使用户能够浏览趋势集合中的项目列表。我按标题对单个项目进行索引,并看到这些标题的搜索结果中只出现了一些标题。
以下是我实现应用索引 API 的方式:
TrendingCollectionActivity
static final Uri BASE_URI_APP = Uri.parse("android-app://" + BuildConfig.APPLICATION_ID + "/mySchema/");
@Override
public void onCreate(Bundle savedInstance) {
// basic setup
mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
...
public void onLoadFinished(Loader<CollectionModel> loader, CollectionModel trendingCollection) {
// adapter & view pager setup ...
mCollectionModel = trendingCollection
// Call the App Indexing API start method after the view has completely rendered
startAppIndexing(mCollectionModel)
}
@Override
public void onStop() {
// other teardown ...
// register end of collection view
stopAppIndexing(mCollectionModel);
}
//View Pager callback to handle individual card/item swipes
@Override
public void onPageSelected(int position) {
// get current fragment, update action bar menus, etc
// ...
// app indexing: register currently visible card view
ItemModel itemModel = mCollectionPagerAdapter.getItemModel(mViewPager.getCurrentItem());
startAppIndexing(itemModel); // implementation very similar to the collection's onCreate()
// register end of previous card view
int prevIndex = mViewPager.getCurrentItem() - 1;
ItemModel prevCard = mCollectionPagerAdapter.getItemModel(prevIndex >= 0 ? prevIndex : 1);
stopAppIndexing(prevCard); // implementation very similar to the colleciton's onStop()
}
private void startAppIndexing(CollectionModel collectionModel) {
mClient.connect()
if (trendingCollection == null) { return; }
final String TITLE = trendingCollection.getHashtag();
final String hostPath = new StringBuilder("collections/").append(trendingCollection.getId()).toString();
final Uri APP_URI_COLLECTIONS = BASE_URI_APP.buildUpon().appendEncodedPath(hostPath).build(); // = android-app://net.kip2.android/myScheme/collections/7091
Action viewAction = Action.newAction(Action.TYPE_VIEW, TITLE, APP_URI_COLLECTIONS);
PendingResult<Status> result = AppIndex.AppIndexApi.start(mClient, viewAction);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "App Indexing API: Recorded trend "
+ TITLE + " view successfully.");
} else {
Log.e(TAG, "App Indexing API: There was an error recording the trend view."
+ status.toString());
}
}
});
}
private void stopAppIndexing(CollectionModel collectionModel) {
if (trendingCollection == null) { return; }
final String TITLE = trendingCollection.getHashtag();
final String hostPath = new StringBuilder("collections/").append(trendingCollection.getId()).toString();
final Uri APP_URI_COLLECTIONS = BASE_URI_APP.buildUpon().appendEncodedPath(hostPath).build();
Action viewAction = Action.newAction(Action.TYPE_VIEW, TITLE, APP_URI_COLLECTIONS);
PendingResult<Status> result = AppIndex.AppIndexApi.end(mClient, viewAction);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d(TAG, "App Indexing API: Recorded trend "
+ TITLE + " view ended successfully.");
} else {
Log.e(TAG, "App Indexing API: There was an error recording the trend view end."
+ status.toString());
}
}
});
mClient.disconnect();
}
有人知道我做错了什么吗?