Getting data into the application with the intention from the link to the browser

I have defined an intent filter to listen on the user schema in my application, but I also need to send data to my application so that I can act accordingly.

What I want to do is send the link to the user (in the browser) that he clicks, and he will deliver it to my application, where it will add some data to the database depending on the URL that he clicked on.

+5
source share
2 answers

You need to embed this data in the path that you add to the URI scheme. Say you configured your activity with the following intent filter with a custom myapp scheme:

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

Now create a link and add all the data you want to use in the URI scheme as query parameters:

 myapp://open?custom_param1=val1 

Then in onCreate you can analyze the intention

 Uri data = this.getIntent().getData(); if (data != null && data.isHierarchical() && activity != null) { if (data.getQueryParameter("custom_param1") != null) { String param1 = data.getQueryParameter("custom_param1"); // do some stuff } } 

Or you can use a service such as Branch , which allows you to combine unlimited data in JSON format into a link that is retrieved by click on the link and the application. This makes this process easier.

+5
source

You should put this category in your intent filter:

 <category android:name="android.intent.category.BROWSABLE" /> 
0
source

All Articles