10

Currently in my app, I have my own URI scheme to detect when user clicks on a particular URI.

Code used in Manifest file is as below:

<intent-filter> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" android:host="com.test/> <action android:name="android.intent.action.VIEW" /> </intent-filter> 

If a user clicks on a link which has my custom URI in browser, It will now popup a options for user to choose my app.

But how do I pass this data which is the link to my app when started for further processing? Basically how do I pass data from browser to my app?

2
  • Why do you set android.intent.action.VIEW twice? Commented Aug 6, 2015 at 18:41
  • @portfoliobuilder Should be once, guess it didn't threw any error if written twice, so would have missed it. Commented Aug 7, 2015 at 1:12

1 Answer 1

13

Suppose that your url is: http://twitter.com/status/1234
You can get the data using the following method.

 // http://twitter.com/status/1234 Uri data = getIntent().getData(); Log.d(TAG, data.toString()); String scheme = data.getScheme(); // "http" Log.d(TAG, scheme); String host = data.getHost(); // "twitter.com" Log.d(TAG, host); String inurl = data.toString(); List<String> params = data.getPathSegments(); String first = params.get(0); // "status" String second = params.get(1); // "1234" 
Sign up to request clarification or add additional context in comments.

2 Comments

I always get null in Paths:( But data is correct and not null.
data.pathSegments is empty

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.