Android应用程序索引自动完成

Android应用程序索引自动完成,android,autocomplete,android-app-indexing,google-voice-search,google-search-platform,Android,Autocomplete,Android App Indexing,Google Voice Search,Google Search Platform,我目前正在我的应用程序中实现谷歌的应用程序索引api和语音搜索功能,但由于谷歌没有在某些设备上搜索我的应用程序,我遇到了一些问题。我测试过的大多数设备都能像预期的那样工作,在这些设备上,我的应用程序中搜索的内容会弹出一个带有自动完成功能的本地搜索。当我的应用程序正常运行时,它会出现在谷歌手机搜索设置中要搜索的应用程序中 然而,由于某些原因,我测试过的某些设备(特别是运行4.3的Galaxy S3和运行4.4.2的Galaxy Note 3)没有在Google手机搜索设置中显示我的应用程序。这反过

我目前正在我的应用程序中实现谷歌的应用程序索引api和语音搜索功能,但由于谷歌没有在某些设备上搜索我的应用程序,我遇到了一些问题。我测试过的大多数设备都能像预期的那样工作,在这些设备上,我的应用程序中搜索的内容会弹出一个带有自动完成功能的本地搜索。当我的应用程序正常运行时,它会出现在谷歌手机搜索设置中要搜索的应用程序中

然而,由于某些原因,我测试过的某些设备(特别是运行4.3的Galaxy S3和运行4.4.2的Galaxy Note 3)没有在Google手机搜索设置中显示我的应用程序。这反过来意味着,尽管应用程序索引api告诉我索引api调用成功,但我的自动完成结果都不会出现。当手机搜索设置中缺少该应用程序时,谷歌语音搜索进入我的应用程序也会失败,而这通常会在说“搜索”时起作用

我在应用程序中设置的深层链接似乎可以工作,而不管自动完成或语音搜索是否工作。这让我相信这个问题甚至可能无法在应用程序中解决

下面是我的清单:

<activity android:name=".StartActivity"
              android:theme="@android:style/Theme.NoDisplay"
              android:noHistory="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <!--Google Voice Search-->
        <intent-filter>
            <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        <!--Deep link-->
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="MyApp"/>
            <action android:name="android.intent.action.VIEW"/>
        </intent-filter>
    </activity>

下面是我在一项活动中调用应用程序索引api的方式:

private void fireNewApplicationIndex(){
    try {
            JSONObject obj; 
            ...

            //The filters have been updated within the running activity
            if(deepLink != null && mClient.isConnected()){
                AppIndex.AppIndexApi.viewEnd(mClient, this, deepLink);
                deepLink = null;
            }

            //Connect the client if it wasn't already
            if(!mClient.isConnected())
                mClient.connect();

            //Report to google the deep link and the auto complete title
            deepLink = Uri.parse(obj.getString(UriHandler.DEEP_LINK));
            PendingResult<Status> result = AppIndex.AppIndexApi.view(mClient, this, deepLink, title, UriHandler.EMPTY_WEB_URI, null);
            result.setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    if(status.isSuccess()){
                        Log.d(TAG, "App Indexing success " + title);
                    } else {
                        Log.d(TAG, "App Indexing failure: " + status.toString());
                    }
                }
            });

        }
    } catch (Exception e) {
        Log.d("App Indexing", e.getMessage() + "");
        if(mClient.isConnected())
            mClient.disconnect();
    }
}
private void fireNewApplicationIndex(){
试一试{
JSONObject对象;
...
//过滤器已在正在运行的活动中更新
if(deepLink!=null&&mClient.isConnected()){
AppIndex.AppIndexApi.viewEnd(mClient、this、deepLink);
deepLink=null;
}
//连接客户端(如果尚未连接)
如果(!mClient.isConnected())
mClient.connect();
//向谷歌报告深度链接和自动完成标题
deepLink=Uri.parse(obj.getString(UriHandler.DEEP_LINK));
Pendingreult result=AppIndex.AppIndexApi.view(mClient,this,deepLink,title,UriHandler.EMPTY_WEB_URI,null);
result.setResultCallback(新的ResultCallback(){
@凌驾
公共void onResult(状态){
if(status.issucess()){
Log.d(标签,“应用程序索引成功”+标题);
}否则{
Log.d(标记“应用程序索引失败:+status.toString());
}
}
});
}
}捕获(例外e){
Log.d(“应用程序索引”,例如getMessage()+);
如果(mClient.isConnected())
mClient.disconnect();
}
}

在对我的测试设备进行了大量调试和比较后,我发现那些无法显示自动完成功能的设备有一个旧版本的谷歌应用程序。为了使应用程序能够被识别并显示自动完成,谷歌应用程序必须是v4.2+