Monday 27 April 2015

Android Deep Linking

App Indexing allows you to connect pages from your website with specific content within your smartphone app. This enables smartphone users who have your app installed to open it directly from relevant mobile search results on Google.

For example, imagine you run a recipe website and have an app that can also show your recipe.
Thanks to the app indexing feature, when a Google searcher on a mobile device is shown one of your recipes as a search result, they will now be able to open that result directly in your app if they have it installed.

Here is how to specify a deep link to your app content:

In your Android manifest file, add one or more <intent-filter> elements for the activities that should be launchable from Google Search results.

Add an <action> tag that specifies the ACTION_VIEW intent action.


Add a <data> tag for each data URI format the activity accepts. This is the primary mechanism to declare the format for your deep links.


Add a <category> for both BROWSABLE and DEFAULT intent categories.

BROWSABLE is required in order for the intent to be executable from a web browser. Without it, clicking a link in a browser cannot resolve to your app and only the current web browser will respond to the URL.

DEFAULT is not required if your only interest is providing deep links to your app from Google Search results. However, the DEFAULT category is required if you want your Android app to respond when users click links from any other web page that points to your web site. The distinction is that the intent used from Google search results includes the identity of your app, so the intent explicitly points to your app as the recipient — other links to your site do not know your app identity, so the DEFAULT category declares your app can accept an implicit intent.

Example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.deeplinkex"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Splash"
            android:label="@string/app_name" >

            <!--
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            -->

            <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.example.com"
                    android:pathPrefix="/android"
                    android:scheme="http" />
          
            </intent-filter>
        </activity>
    </application>

</manifest>

Reading a Data from Incoming Intents:

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

               Intent intent=getIntent();
               String action=intent.getIntent();
              Uri data=intent.getData();

}

Otuput:

No comments:

Post a Comment