James
James

Reputation: 191

How do I receive a "Share URL" from browser?

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();
    }
}

Upvotes: 13

Views: 6592

Answers (2)

poplitea
poplitea

Reputation: 3737

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);

Upvotes: 12

Reno
Reno

Reputation: 33792

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);

Upvotes: 5

Related Questions