12

I read this ( How do I handle the browser's "share page" intent in android? ) which I can get the Share link to detect my app, now how do I get Activity to receive the URL?

Found Answer:

Intent intent = getIntent();
if (savedInstanceState == null && intent != null) {
    Log.d(TAG, "intent != null");

    if (intent.getAction().equals(Intent.ACTION_SEND)) {
        Log.d(TAG, "intent.getAction().equals(Intent.ACTION_SEND)");
        String message = intent.getStringExtra(Intent.EXTRA_TEXT);
        messageText.setText(message);
        receiverText.requestFocus();
    }
}
Community
  • 1
  • 1
James
  • 181
  • 3
  • 13

2 Answers2

11

When your application receives the "Share page" from the browser, you could also get the title of the webpage:

String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
poplitea
  • 3,585
  • 1
  • 25
  • 39
5

Once you have created an intent filter, your activity should pop up in the list of activities listening to the share link. Then use this in your activity:

String url = getIntent().getStringExtra(Intent.EXTRA_TEXT);
Reno
  • 33,594
  • 11
  • 89
  • 102
  • Thanks, this is what I put in my OnCreate for my Main Activity: 'Uri myI = getIntent().getData(); String myItext = myI.toString(); mEditText.setText(myItext);' But it force closes once I try to convert it to string (line #2) – James Jun 20 '11 at 17:44
  • @James Oh my bad, when I answered this I had no access to an emulator/device to test it. I was going to suggest using extra string, but you've found the answer. Good work – Reno Jun 21 '11 at 10:27