简体   繁体   中英

Android App Indexing Autocomplete

I am currently implementing Google's app indexing api and voice search capabilities in my application, and am running into problems with Google not searching my application on certain devices. Most devices I've tested on work like expected following their code lab example where a local search with autocomplete pops up for content searched in my application. My application appears in the apps to search for in the Google Phone Search settings when it works correctly.

However, for some reason certain devices I've tested (specifically a Galaxy S3 running 4.3 and a Galaxy Note 3 running 4.4.2) don't have my application appear in the Google Phone Search settings. Which in turn means that none of my autocomplete results appear despite the App Indexing api telling me that the index api call was successful. When the app is missing from the Phone Search settings, Google voice search into my application also fails, when it would usually work with when saying "Search <-MyApplication-> for <-Content->".

Deep links that I have set up in my application seem to work regardless of autocomplete or voice search working. Which leads me to believe this issue might not even be something I can fix within the application.

Here's a look at my manifest:

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

And here's how I call the app indexing api in one of my activities:

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

After much debugging and comparing my test devices, I found that the devices failing to show autocomplete had an older version of the Google app. In order for applications to be recognized to be searched and display autocomplete the Google app must be v4.2+!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM