I have defined an intent filter to listen for a custom scheme in my app but I must also send data to my app so I can act accordingly.
What I want to accomplish - send a link to the user (in a browser) which he clicks and it takes him to my app where it will add some data to the database depending on the URL he clicked on.
You'll need to embed this data into the path that you append to the URI scheme. Let's say you set up your Activity with the following intent filter with the custom scheme of myapp:
<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 append all of the data you want to the URI scheme in the form of query parameters:
myapp://open?custom_param1=val1
Then, in onCreate
, you can parse the intent
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 like Branch that lets you bundle unlimited data in JSON format into a link, that is retrieved on link click and app open. It makes this process much easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With