簡體   English   中英

Android App索引自動完成

[英]Android App Indexing Autocomplete

我目前正在我的應用程序中實現Google的應用程序索引API和語音搜索功能,並且遇到了Google無法在某些設備上搜索我的應用程序的問題。 我在其代碼實驗室示例中測試的大多數設備均按預期工作,其中彈出帶有自動完成功能的本地搜索以查找在我的應用程序中搜索到的內容。 當我的應用程序正常運行時,它會出現在應用程序中以在Google Phone搜索設置中進行搜索。

但是,由於某些原因,我測試過的某些設備(特別是運行4.3的Galaxy S3和運行4.4.2的Galaxy Note 3)沒有將我的應用程序顯示在Google Phone搜索設置中。 這反過來意味着盡管App Indexing api告訴我index api調用成功,但我的自動完成結果都沒有出現。 當“電話搜索”設置中缺少該應用程序時,當說出“在<-MyApplication->中搜索<-Content->”時,通常無法正常使用Google語音搜索。

無論自動完成或語音搜索如何工作,我在應用程序中設置的深層鏈接似乎都可以工作。 這使我相信這個問題甚至可能不是我可以在應用程序中解決的。

看一下我的清單:

<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();
    }
}

經過大量調試並比較了我的測試設備,我發現未顯示自動完成功能的設備具有舊版的Google應用。 為了能夠識別要搜索的應用程序並顯示自動完成功能,Google應用程序必須為v4.2 +!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM