我正在实现谷歌提供的应用索引 API。如此处所示,我在 onStart() 方法中连接了客户端,如下所示:
APP_URI = Uri.parse(baseAppUri + slug);
WEB_URL = Uri.parse(baseWebUri + slug);
Action viewAction = Action.newAction(Action.TYPE_VIEW, title, WEB_URL, APP_URI);
// Call the App Indexing API start method after the view has
// completely
// rendered
// Call the App Indexing API view method
PendingResult<Status> result = AppIndex.AppIndexApi.start(mClient, viewAction);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
CommonLib.ZLog(TAG, "App Indexing API: Recorded " + title + " view successfully.");
} else {
Log.e(TAG, "App Indexing API: There was an error recording the view." + status.toString());
}
}
});
在用户完成页面后,即用户按下后退按钮,我在 onStop() 中调用 AppIndexApi.end,如下所示:
@Override
protected void onStop() {
// Call end() and disconnect the client
Action viewAction = Action.newAction(Action.TYPE_VIEW, title, APP_URI);
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 " + title + " view end successfully.");
} else {
Log.e(TAG, "App Indexing API: There was an error recording the view." + status.toString());
}
}
});
mClient.disconnect();
super.onStop();
}
问题是回调没有被执行。resultcallback 中的所有情况都没有记录状态并且执行直接跳转到mClient.disconnect.
并且标题没有显示在谷歌应用程序的搜索结果中。
知道我在哪里出错了吗?