Here is my activity structure: SplashActivity -> MainActivity. My MainActivity has a Spinner that is populated from ContentProvider. Based on Spinner selection, I present different content to the user. The content map perfectly to the content on my website. My website has long been indexed and is working fine. Now I want to index said content in my app.
Here is my manifest
<activity android:name=".activities.SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity"/>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="www.business.com"
android:scheme="http"/>
<data
android:host="www.business.com"
android:scheme="https"/>
<data
android:host="business.com"
android:scheme="http"/>
<data
android:host="business.com"
android:scheme="https"/>
<data
android:host="/*"
android:scheme="business"/>
<data android:scheme="android-app"
android:host="com.business.android" />
</intent-filter>
</activity>
Here is the app-indexing portion of my MainActivity
@Override
public void onStart() {
super.onStart();
appIndexingTask();
}
private void appIndexingTask() {
new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
try {
if(null == mNdxClient){
mNdxClient = new GoogleApiClient.Builder(MainActivity.this)
.enableAutoManage(MainActivity.this, MainActivity.this)
.addApi(AppInvite.API).addApi(AppIndex.API)
.build();
}
if(!mNdxClient.isConnected()){
mNdxClient.blockingConnect();
}
if (mNdxClient != null && mNdxClient.isConnected()) {
HashMap<Uri, Action> indexedActions = new HashMap<>();
List<Content> contentList = getAllFromContentProvider();
for(Content c: contentList){
Uri uri = Uri.parse(FirebaseUtils.appIndexingLink(c.getUrl()));
Action action = getAction(c.getName(), c.getDescription(), uri);
AppIndex.AppIndexApi.start(mNdxClient, action);
indexedActions.put(uri, action);
}
for (Action action : indexedActions.values()) {
AppIndex.AppIndexApi.end(mNdxClient, indexedActions.get(action));
}
}
} catch (Exception e) {
//abandon task
}
return null;
}
public Action getAction(String title, String description, Uri uri) {
Thing object = new Thing.Builder()
.setName(title)
.setDescription(description)
.setUrl(uri)
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
}.execute();
}
Here is the Utility method
public static String appIndexingLink(String urlString){
String appNdx= new StringBuilder("android-app://").append(BASE_URL).append(urlString).toString();
return appNdx;
}
Finally, in gradle I am using
classpath 'com.google.gms:google-services:3.0.0'//project level
//app level
compile 'com.google.android.gms:play-services-appindexing:9.0.0'
compile 'com.google.firebase:firebase-core:9.0.0'
compile "com.google.firebase:firebase-messaging:9.0.0"
compile "com.google.firebase:firebase-invites:9.0.0"
Some important points
- App-Invite works: I can send an invite and then open the invite (code not shown)
- Deep Linking works, if I send myself a link to my site, when I open the link on my android phone, it opens it with the app perfectly.
- Google Search has not indexed my app
- Fetch as Google fails with “URI unsupported” whether I point to Play Store or local apk.
Notice the filter
<data android:scheme="android-app"
android:host="com. business.android" />
I don’t see it anywhere in documentations. But nothing else works. So I added it. It’s still not working.
Although I am not showing logging. I am logging and so I know that the app-indexing code runs.