I have implemented deep linking as part of app indexing according to the official docs. I'm facing a few different but related problems with the search auto-completion part:
- Auto-completion results show only the last opened item (previously accessed items seem to be overwritten). For example, say in my app's list view of trending topics/collections the user opens item A ("shortvideos1" in the screenshot attached), resumes the feed and then opens item B ("shortvideos2"). A partial search of "shortvid" only shows the latter: "shortvideos2". Full search for "shortvideos1" yields nothing. Suggests that only the latest item shows up in the search results list.
- Some content accesses are missing from the results list. I have a view pager that enables the user to swipe through a list of items in a trending collection. I index the individual items by their titles, and see only some of the titles appear from the search results by those titles.
Here is how I implement the app indexing 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();
}
Anybody know what I'm not doing correct?