Here is my activity structure: SplashActivity → MainActivity. My MainActivity has a Spinner, which is populated from ContentProvider. Based on the choice of Spinner, I present the user with various content. A content map is perfect for content on my website. My site has been indexed for a long time and it works fine. Now I want to index the specified content in my application.
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 indexing part of my MainActivity application
@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) {
}
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 use
classpath 'com.google.gms:google-services:3.0.0'
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 invitation and then open an invitation (code not shown)
- Deep Linking , , Android-, .
- Google Search
- Google "URI", Play Store apk.
<data android:scheme="android-app"
android:host="com. business.android" />
. . . .
. , , .