Mobile Computing and Mobile Application Development is the Future,made me to think that Mobile apps and computing,optimization is going to be the next big thing on Earth.As i have experienced Android development as well As Web Development i could correlate the things like Google Search, Mobile Views and so on.As every one knew Mobile apps search are comparatively different from Desktop search,Where we could directly visit the Websites and make purchase and move on.But, in the case of Mobile it is going to be however hurting experience for both users and Developers to maintain and interact with Webview in Smartphones.So,Google came up with Solution to show and index apps on Google search on Signed in Browser for Android and show relevant apps that can be view with Mobile apps.
So,if it is site we could submit the sitemaps to Google Bots and Crawl our contents for indexing,but in case of apps... so,here comes Indexing API to index your app contents and correlate the contents with web and mobile and Show suggestions on Google Mobile Search app.
We are just going to Create some content in app and try to show in Google Suggestion using Relevant Keywords.We will deal without web url in this post.
android-app://com.example.app/<scheme>/<host>
However you can use your own custom scheme,Follow the given code below for example,
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<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:scheme="cricket"
android:pathPrefix="/sachin" />
</intent-filter>
</activity>
public class MainActivity extends ActionBarActivity {
GoogleApiClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.APP_INDEX_API).build();
public void onStart(){
final Uri WEB_URL = null;
So,if it is site we could submit the sitemaps to Google Bots and Crawl our contents for indexing,but in case of apps... so,here comes Indexing API to index your app contents and correlate the contents with web and mobile and Show suggestions on Google Mobile Search app.
Prerequisites :
Download : Code at GitHub
- Android Phone with Play Account
- Android Studio (Preferable because of Gradles )
- Some Patience :D and Simple App to test it out.
Procedure :
As i don't write android app tuts here,Just Start Creating Simple App with main activity with some contents and title with relevant key title.You can refer the Source code from my Github Repo.There are two ways of App indexing as i have categorized with Web URL and Without Web URL.
- With Web URL we could index the content of the app in Google Mobile Browser Search by showing your App and which will lead to open the App from native browser.
- Without Web URL we could index the content of the app in Google Search Suggestion in Google Search App which leads to open the content of the apps.(BTW the search result display is not mentioned as far as i have read).
Configure Your APP :
Just we have to configure your app manifest to accept the intents and make way to launch your app by other apps and receive data.Important thing in app indexing is having correct App URI and Keywords.Your app uri must be kind of,android-app://com.example.app/<scheme>/<host>
However you can use your own custom scheme,Follow the given code below for example,
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<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:scheme="cricket"
android:pathPrefix="/sachin" />
</intent-filter>
</activity>
Test your app using adb command :
adb shell am start -a android.intent.action.VIEW -d "cricket://sachin" com.ivb.app.app_indexing
This must start the activity successfully without the errors! check out the code for manifest here.
Without Web URL :
First of all let us assume that we have website with content and displaying in Google search results and we need to link that with our Android app.
There are two steps to set up this App indexing API :
- First implement the API in the Android application with few lines of code,Check out the simple Activity title to be indexed here.
Setting up Google API client :
public class MainActivity extends ActionBarActivity {
GoogleApiClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mClient = new GoogleApiClient.Builder(this).addApi(AppIndex.APP_INDEX_API).build();
using onStart method make your API call after loading your UI generally,make your web URL as null,since we don't deal with the with Web indexing now.we will deal with with web url in next post.
public void onStart(){
super.onStart();
mClient.connect();
final String TITLE = "sachin tendulkar masterblaster";
final Uri APP_URI =
Uri.parse("android-app://app.ivb.com.app_indexing/cricket/sachin");final Uri WEB_URL = null;
PendingResult<Status> result = AppIndex.AppIndexApi.view(mClient, this,
APP_URI, TITLE, WEB_URL, null);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d("success", "App Indexing API: Recorded recipe view successfully.");
} else {
Log.e("error", "App Indexing API: There was an error"
+ status.toString());
}
}
});
}
Using onStop() method and disconnect the Client of GoogleAPI service
public void onStop(){
super.onStop();
final Uri APP_URI =
Uri.parse("android-app://app.ivb.com.app_indexing/crciket/sachin");
PendingResult<Status> result = AppIndex.AppIndexApi.viewEnd(mClient, this, APP_URI);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d("success", "App Indexing API: Recorded recipeview end successfully.");
} else {
Log.e("error", "App Indexing API: There was an error"
+ status.toString());
}
}
});
mClient.disconnect();
}
super.onStop();
final Uri APP_URI =
Uri.parse("android-app://app.ivb.com.app_indexing/crciket/sachin");
PendingResult<Status> result = AppIndex.AppIndexApi.viewEnd(mClient, this, APP_URI);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.d("success", "App Indexing API: Recorded recipeview end successfully.");
} else {
Log.e("error", "App Indexing API: There was an error"
+ status.toString());
}
}
});
mClient.disconnect();
}
Note: After implementing this you can check your Google Search using Google Now/Search app Showing suggestion when you search relevant to your keywords.
My Results : Code hosted on GitHub
Well we had seen how to index our app content with keywords and APP-URI through APP-INDEXING API.However before implementing this API,Just test it the App-uri using adb tool and check whether it is resolved successfully and opening your app.
Lets implement with WEB url in next post with live App with search result indexing
For Suggestions/Help/hug/bug or projects just drop me a mail to [email protected] or chat with me in Facebook/Google+ hangout or connect with me in Twitter for recent updates.Share is care and sign up for newsletter for recent updates in blog.