4

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?

6
  • <a href="example://activityone">link</a> Commented Jul 13, 2016 at 8:26
  • This doesn't work when embedded in email Commented Jul 13, 2016 at 13:39
  • 1
    For email compatibility, use real deeplink or chrome intents: developer.chrome.com/multidevice/android/intents Commented Jul 13, 2016 at 14:19
  • Can you give an example? Commented Jul 13, 2016 at 16:38
  • Examples are in the link Commented Jul 13, 2016 at 16:41

2 Answers 2

11
+50

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.

  • They aren't always treated as links
  • You don't own them like you own a domain name (host).

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.

Sign up to request clarification or add additional context in comments.

6 Comments

How can I put this uri in an email, and when it is clicked, it will launch the app?
I've updated my answer to include just the link and more information about the app selection/launch process when it is clicked. You can send it to yourself in an email to test.
If you're using gmail (and maybe other email clients), you have to explicitly tell it that you want http://example.com/activityone?foo=bar to be treated as a link and not plain text. Highlight the text and click "Insert Link" in the toolbar down by the send button.
I knew the http will work and I did that before I posted this question. I am looking for how to open the custom uri (example://activityone?foo=bar), I want to be able to open the deep link even if the scheme is not http.
The problem is not the setup in your app. The problem is that any custom scheme will most likely NOT be clickable in any SMS or email client. See this SO post.
|
2

Non-standard URL schemes (which is what example:// is) aren't always treated as links. Your best option is to somehow wrap that URL inside a link that the app CAN recognize (http:// or https://), and then take care of opening your app later, usually by way of some sort of automatic redirect. This is how we handle things to make sure the app always launches no matter where the link is opened.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.