Android 应用索引自动完成

标签 android autocomplete android-app-indexing google-voice-search google-search-platform

我目前正在我的应用程序中实现 Google 的应用程序索引 API 和语音搜索功能,但遇到了 Google 无法在某些设备上搜索我的应用程序的问题。我测试过的大多数设备都按照预期的方式工作 code lab example对于在我的应用程序中搜索的内容,会弹出带有自动完成功能的本地搜索。当我的应用程序正常工作时,它会出现在 Google Phone Search 设置中要搜索的应用程序中。

但是,出于某种原因,我测试过的某些设备(特别是运行 4.3 的 Galaxy S3 和运行 4.4.2 的 Galaxy Note 3)没有让我的应用程序出现在 Google Phone Search 设置中。这反过来意味着尽管 App Indexing api 告诉我索引 api 调用成功,但我的自动完成结果都没有出现。当手机搜索设置中缺少该应用程序时,谷歌语音搜索我的应用程序也会失败,而当它通常在说“搜索 <-MyApplication-> for <-Content->”时可以正常工作。

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

这是我的 list :

<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>

下面是我在我的一项 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();
    }
}

最佳答案

经过多次调试和比较我的测试设备后,我发现无法显示自动完成功能的设备使用的是旧版 Google 应用程序。为了识别应用程序以进行搜索并显示自动完成功能,Google 应用程序必须为 v4.2+!

关于Android 应用索引自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28972233/

相关文章:

Google 搜索中的 Android 应用程序索引

Android,检查 URL 存在后在 WebView 中打开 URL

android - 在 Android 上启用安全网设备检查 API 的具体步骤是什么

autocomplete - Sublime Text 3 - 来自另一个文件的 SASS (scss) 自动完成变量

javascript - jQuery 自动完成 : How to complete multiple fields when entering data into one of them?

reactjs - 当我按 "."键时,Visual Studio Code 自动完成。有办法禁用吗?

ios - Google App Indexing - 如何测试它?

android - 如何在android listview中实现fling

android - 无法在Android Studio 2.3.3中创建新项目

android - Google App Indexing 不适用于描述字段,但适用于标题字段