Reputation: 6863
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:
Here is how I implement the app indexing API:
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?
Upvotes: 0
Views: 281
Reputation: 366
Regarding your first point, the expected behavior is that auto-complete presents all results that match or partially match your query on Google App Search, being that the results presented were viewed by the user at some point in the past. Can you please detail more on the flow of publishing your deep links using the API? Are you publishing all your content deep links when opening the App or publishing the deep link only when the content is viewed by the user?
On your second point, I must know if you opened the items of your trending collection. If not, then the reason they don't appear in the auto-completion suggestions is the same as in the previous point. The content must be opened by the user, before it can appear on the auto-completion suggestions.
Hope this helps with your doubts and let me know if you have anymore questions.
Cheers.
Upvotes: 1