-->

To have Autocomplete feature of app indexing is it

2019-07-25 10:11发布

问题:

I have added features of App indexing and deep linking for my Game app as a plugin .. deep linking is working properly , the feature of app indexing i.e Autocomplete is not working,.. as ,

PendingResult<Status> result=AppIndex.AppIndexApi.end(mClient,getAction());

result.setResultCallback(new ResultCallback<Status>()

Above Code: Call back records of the visited page;

And shows in play store whenever trying to search similar to the page.

But it is not showing me Autocomplete ..

回答1:

In the manifest, the activity that needs to be deeplinked(openable by a URI defined by you) should have the following structure :

<activity
                android:name=".MyActivity"
                <intent-filter android:label="@string/app_name">
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <!-- Accepts URIs that begin with "http://my-app.com/mypage" -->
                    <data android:scheme="http"
                        android:host="my-app.com"
                        android:pathPrefix="/mypage" />
                </intent-filter>
</activity>

In your activity, define a URI which uniquely identifies that activity. It should be in the following format : //android-app://<package_name>/<scheme>/[host_path]).

For example :

private static final Uri MY_URI = Uri.parse("android-app://com.myapp/http/my-app.com/mypage/");

Also, you'll need to use an instance of the GoogleApiClient.

private GoogleApiClient mClient;

In the onCreate function, initialize the client :

mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.APP_INDEX_API).build();

Then, wherever appropriate in the code, connect to the client and create an Action which will be passed to the AppIndex API.

For example :

// Connect your client
mClient.connect();
// Define a title for your current page, shown in autocompletion UI
final String TITLE = "My Title";
//Define an action
Action viewAction = Action.newAction(Action.TYPE_VIEW, TITLE, MY_URI);

// 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()) {
                        Log.d(TAG, "App Indexing API: Recorded view successfully.");
                    } else {
                        Log.e(TAG, "App Indexing API: There was an error recording the view."
                                + status.toString());
                    }
                }
            });

Finally, disconnect the GoogleApiClient instance in the onStop Method :

mClient.disconnect();

I would suggest that you go through the following tutorial on Google CodeLabs for AppIndexing and DeepLinking. You would require some understanding of how deep linking works before you can implement app indexing properly.

https://codelabs.developers.google.com/codelabs/app-indexing/#0