I am having a list of offers in my application and there is a share button on every list item.I am using deep link to open a offer detail activity of my application when any user clicks on the shared link.i am in a situation that my detail page activity is being triggered when someone clicks the link ,But how can i know ,which offer detail activity to show when some one clicks on the shared deep link .
The manifest file will remain same as specified in this link https://developer.android.com/training/app-indexing/deep-linking.html
But you can provide the extra data in the link you send to the user as www.example.com/gizmos?key=valueToSend
then in the activity you can do something like
Uri data = intent.getData();
data.getQueryParameter("key");
Following @Vikas answer here is a simplified way to do this -
Application 1: This application will send data to another app through deeplinking
String deepUrl = "app://anotherapp?key1=value1&key2=value2"; //key1 and key2 for sending data to other application
Intent intent = new Intent (Intent.ACTION_VIEW);
intent.setData (Uri.parse(deepUrl));
startActivity(intent);
this will start a intent for lunching another app with some data as path parameter with the link.
Now we need to handle the corresponding link to handle in our second application like this:
Application 2's Manifest file to handle deeplinking add intent filter
to the corresponding activity which will handle the data, in my case MainActivity
will do
<activity android:name=".MainActivity">
...
<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="anotherapp"
android:scheme="app" />
</intent-filter>
</activity>
and then in your activity you can get data like this:
Intent intent = getIntent();
Uri data = intent.getData();
String data1= data.getQueryParameter("key1"); // you will get the value "value1" from application 1
String data2= data.getQueryParameter("key2");
For more information about deep linking see the official link
Notes: If Application 2 not installed in your phone then you can get an error from application 1 stating ActivityNotFoundException
Supposing that you generate a separate share link for each item. You could send some parameters along with the deep link URL and then receive them in the App. Any kind of an ID would suffice. (Source: this)
<intent-filter android:label="@string/filter_title_viewgizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with "example://gizmos”
<data android:scheme="example"
android:host="gizmos" />
-->
</intent-filter>
Taking up this example, if the app deep links here, you can receive your intent in the corresponding activity (Here: com.example.android.GizmosActivity) and extract information from there itself.
© 2022 - 2024 — McMap. All rights reserved.