1

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

PN10
  • 1,888
  • 3
  • 23
  • 34
  • No. It is not necessary to publish latest app on play store for the autocomplete feature to work. Please post your code in greater detail so that people can help you out. – Umang Mathur May 17 '16 at 11:38
  • yes it is not necessary.. Auto complete is working properly now... Thank you . But when i click on Auto complete page option , it is not linking me to the Game App . means whenever i click on Auto complete it is not opening the Game . is it necessary that configured build should be published to check it ? – Abhinandan Dharmadhikari May 17 '16 at 12:30
  • Please post code of your manifest file where you've handled deeplinks. I hope you've defined deeplink URL scheme in the manifest for the activity that needs to be opened when you click on the auto complete option. – Umang Mathur May 17 '16 at 12:35
  • please check the manifest i was not able to post in comments so posted in answer. – Abhinandan Dharmadhikari May 17 '16 at 12:43

1 Answers1

3

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Umang Mathur
  • 833
  • 1
  • 10
  • 32