Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give Intent Data in Deep Link

I have updated manifest file to support deep linking. I have checked it from Run(Edit Configuration), and it opens the specified activity.

Now i need to send some data with the deep link. So what should be the procedure of it. I have added another data attribute, but i don't understand how to get data in the Activity in the same key/value fashion.

I am getting Intent like this in Activity

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

intent.getData() has this value= myapp://videodeeplink

I have read some articles and tutorials regarding this, but i am just unable to get this. Kindly guide me how to put and get some data in deep linking.

myapp://videodeeplink

<activity
    android:name=".VideosListActivity"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme" >

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="myapp" android:host="videodeeplink"/>
        <data android:scheme="videoURL" android:host="videoURL"/>
    </intent-filter>


</activity>
like image 227
dev90 Avatar asked Feb 15 '17 10:02

dev90


People also ask

What is link intent?

A deep link is an intent filter system that allows users to directly enter a specific activity in an Android app. However there is an issue about this process. When a user click an URL, it might open a dialog which asks the user to select one of multiple apps handling the given URL.

What is a deeplink example?

In the context of the World Wide Web, deep linking is the use of a hyperlink that links to a specific, generally searchable or indexed, piece of web content on a website (e.g. "http://example.com/path/page"), rather than the website's home page (e.g., "http://example.com").

How do I create a deeplink URL?

Click Add Navigation Icon, then select Add a Web URL. Give it a name. Click Show URL options, then select "Deeplink app URL." Add your deeplink URL to the textbox labelled "Deeplink app URL" and a backup link to the textbox labelled "URL."

What is deeplink redirect?

Deep links send mobile device users directly to relevant pages in your app rather than your website. Users click on ads and go directly to your app pages. You can use deep links in many Google Ads products, including App campaigns for engagement, App dynamic remarketing, and Search, Shopping, and Display campaigns.


1 Answers

To send the data you should add pathPrefix parameter in your data tag like below, so that later we can parse it in the Activity/Fragment where you call it.

 <data
     android:host="@string/host"
     android:pathPrefix="path"
     android:scheme="@string/schema" />

Now when you want to parse it you can use pathSegments in Android, like below using the intents to obtain the data inside.

mainIntent = getIntent();
if (mainIntent!=null && mainIntent.getData()!=null
    && (mainIntent.getData().getScheme().equals("http"))){
        Uri data = mainIntent.getData();
        List<String> pathSegments = data.getPathSegments();
        if(pathSegments.size()>0)
        String prefix=pathSegments.get(0); // This will give you prefix as path
}
like image 101
Gautam Avatar answered Oct 04 '22 01:10

Gautam