For example, there is an uri example://activityone?foo=bar which can open up an application and launch one of the activity by this adb command
adb shell am start -W -a android.intent.action.VIEW -d "example://activityone?foo=bar" com.example.deeplinking
Are there any other ways to launch the android app through this uri (example://activityone?foo=bar)? How can I put this uri in an email, and when it is clicked, it will launch the app?
First, you should read the documentation for this: Intents and Intent Filters. Specifically the section "Receiving an Implicit Intent".
As others have stated, using a custom scheme for this has issues.
So you should define an activity in you Manifest with an intent filter for your host and use a real scheme. See the "Action Test", "Category Test" and "Data Test" sections of the Intent & Intent Filters documentation to see how to configure this for your specific use case.
<activity android:name="com.example.app.ActivityOne">
<intent-filter>
<data android:scheme="http"/>
<data android:host="example.com"/>
<data android:path="/activityone"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
Then you will be able to use a link like the following.
http://example.com/activityone?foo=bar
Since this is an http link the system will ask the user to choose which app to open it with (your app or their preferred browser). If they choose your app it will start ActivityOne which can get the query data like so.
public class ActivityOne extends Activity {
@Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
Uri uri = intent.getData();
String foo = uri.getQueryParameter("foo");
}
}
If you use a custom scheme in the intent filter then you will (most likely) be the only app registered to handle that intent and the user will not have to select your app. However, it will be much harder for you to include a link with a custom scheme in an email. Most email clients will not recognize anything with a custom scheme as a link and it will not be clickable.
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