Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. Android

Optimize Your Mobile Application for Google

Final product image
What You'll Be Creating

Have you ever wondered how those mysterious links pointing to apps appear in your search results when you search the web with Google? How can app developers make sure their apps are displayed here?

In this tutorial, I will demonstrate how to achieve this effect for your apps.

1. What's App Indexing?

Google App Indexing (now re-branded Firebase App Indexing), enables native apps to be listed in Google search results, as if they were normal webpages. The app entries, which would appear together with normal webpage entries, are displayed when a relevant search query is submitted from an appropriate device's browser. The feature is currently supported on Android and iOS platforms.

Why Do Developers Need It?

App Indexing maximizes a developer's chances of success, because it performs two important tasks simultaneously.

Firstly, it improves and enhances the mobile user experience. If an app relevant to a search query is found, the user is given the option to install the app or directly launch the app (if it is already installed on the device), without even having to leave the browser. Thus, the users will have a positive first impression about such an app, and they will subconsciously appreciate the fact that the app managed to appear within the right context, and that it provided them with several options to consider.

Secondly, it helps developers promote their apps directly via Google's search engine. Developers can harness this mechanism to drive traffic directly to their apps and increase the download count dramatically.

How Is It Technically Possible?

App Indexing works its magic with a fairly simple but clever way of establishing a relationship between an app and its website, aptly named "site association". The workflow consists of several steps:

  1. Adding an Intent Filter to support URLs and Google Search
  2. Associating a website with the app
  3. Adding App Indexing API code

2. Let's Build It

Now that we have an idea of the workflow, we'll proceed with each step, and finally, test our implementation on Android Studio. So, we'll create a new Android Project on Android Studio IDE. You'll need to have Android Studio 2.0 or a higher version installed on your machine. Create a new Android Project with an Empty Activity. I have used MyApp as the name of my new Android Project.

Create a new Project in Android Studio

Step 1

We'll start by adding an Intent Filter to support URLs and Google Search. Intents are the communicating agents between Android app components, and using Intent Filters is the standard way of introducing an implicit intent into your app. 

An implicit intent in your app enables it to request that the OS evaluate all the matching registered components (possibly within other installed apps) and select one of them, thus making it possible to perform a certain task using some other app installed on the system. An explicit intent, by contrast, directly specifies a target app component, so that only the specified component will be called upon to perform the action. You can read more on Intents and Intent Filters on the Android Developers website. 

Now, we'll get started creating an Intent Filter.

  • Open the AndroidManifest.xml file.
  • Select an <activity> element with the cursor.
  • Right-click while the selection is on, and then select Generate from the pop-up menu.
  • Further select URL from the secondary pop-up menu.
Select Generate from the pop-up menu

You'll see that Android Studio has added some additional code to your AndroidManifest.xml file. You can change the attributes of the <data> element of the generated code to fit your requirements. In my case, I have provided values related to my demo website.

Be sure to provide the necessary values for both http and https schemes.

Step 2

Now we need to associate a website with our app.

You will need to have verified the web URL that you wish to associate with your app using the Google Search Console. Just log in to the Search Console with your Google account and you'll find easy-to-follow instructions for verifying the URL.

You can also find detailed instructions on how to define the structure of the associated website to match that of your app in the Firebase App Indexing Guide. However, since we are only testing the app using Android Studio, we won't need to explore those details in this tutorial.

For our testing purposes, all we need is a live web URL verified by Google. The attributes you provide for the <data> element in Step 1 must correspond to this verified web URL, which must be fully functional.

Step 3

Finally we'll add App Indexing API code. Android Studio provides an automated way of doing this:

  • Open the MainActivity.java file of your Android Project.
  • Select the word onCreate with the cursor.
  • Right-click while the selection is on, and select Generate from the pop-up menu.
  • Further select the App Indexing API Code from the secondary pop-up menu.
Select the App Indexing API Code from the secondary pop-up menu

You'll see the auto-generated code added by Android Studio to your MainActivity.java file. Be sure to edit the links of the Uri.parse() function, so that they will correctly point to the URLs associated with your app.

3. Testing It

Now, we'll test our work on Android Studio, to make sure that our App Indexing implementation works correctly. First, make sure that you are connected to the Internet. Then, on Android Studio, select Tools > Android > Google App Indexing Test.

On Android Studio select Tools  Android  Google App Indexing Test

After some time, a screen similar to the one below will appear. The passing test results assure you that App Indexing will work correctly in your app.

Test result screen showing test passed


App Indexing is a useful feature for your app to attract more downloads, and it will definitely help you target a wider user base as a developer. In this tutorial, we checked only whether our App Indexing implementation works correctly, but not how exactly the user perceives the functionality resulting from the implementation. You can proceed to that next level by finding more information in the Firebase, Google Webmasters, and Android Studio App Indexing Help websites.

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.