Reputation: 1982
I want to share a link so that when the other user clicks that link, it opens my app with some Intent data that I can process.
Intent i= new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject");
i.putExtra(android.content.Intent.EXTRA_TEXT, "xyz.com/blah");
i.putExtra("important stuff", "important stuff");
startActivity(Intent.createChooser(i, "Share via"));
I have also added this in manifest:
<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:scheme="http" />
<data android:scheme="https" />
<data android:host="xyz.com" />
</intent-filter>
So on clicking the shared text, my app opens up. Now I want to work in my app according to the important stuff
. However, on clicking it, (e.g. from Whatsapp), I only get the following in the received intent.
String name: com.android.browser.application_id
Value in key: com.whatsapp
How can I get back the important stuff
I sent on the intent?
Upvotes: 0
Views: 386
Reputation: 1007554
How can I get back the important stuff I sent on the intent?
You don't.
While you are certainly welcome to put random extras on Intents
, do not expect other apps to do anything with them. In particular, there is nothing in the ACTION_SEND
documentation requiring implementers of ACTION_SEND
to do anything with random extras, let alone somehow get them back to you.
Similarly, while you are welcome to invent new HTTP headers, there is no requirement that a Web server pay attention to them, let alone send them back to you in a response.
Instead, replace xyz.com/blah
with xyz.com/important/stuff
(or possibly xyz.com/blah?important=stuff
), and get the data out of the Uri
used to start your activity. You get this Uri
via getIntent().getData()
in your activity's onCreate()
method (or possibly getData()
on the Intent
passed to onNewIntent()
, depending on your manifest settings and whether an existing instance of this activity already exists).
Upvotes: 2