Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Use Deep Linking in Android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 169
    Comment on it

    In the below example code I have enabled deep linking. Let's consider, you have shared your app in social network like, Gmail, Facebook, Whatsapp etc. When users click on the link you shared then your app will open, if it's installed in his android device.

    To enable a deep link to your app content, add an intent filter that contains these element and attribute value in your manifest-

    <action>- ACTION_VIEW intent action in such a way that the intent filter can be reached from Google Search.

    <data> - This will add one or more <data>tags, where each tag represents a URI that  the activity accept.

    <category>-The next step is to add the BROWSABLE category. The motive behind adding the BROWSABLE category is to make the intent filter easily accessible from a web browser. Without using this category ,the activity can be started only with an explicit intent.


    Now see below  In manifest file ,how to specify an intent filter in the a manifest file.The URI is”http://example.com/testdeeplinking”-

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http"
                android:host="example.com"
                android:pathPrefix="/testdeeplinking" />
            <!-- note that the leading "/" is required for pathPrefix-->
            <!-- Accepts URIs that begin with "example://testdeeplinking -->
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
    


    Now see how to Read Data from Incoming Intents-
    Let’s now talk about what you need to keep in mind while using data provided by the intent to determine what you need to render. You need to call the getData() and getAction() methods, which will help you retrieve the data and action associated with the incoming Intent .

     

    Activity  code-

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

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: