Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
    }
}
like image 607
James Avatar asked Jun 20 '11 15:06

James


2 Answers

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);
like image 112
poplitea Avatar answered Oct 21 '22 15:10

poplitea


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);
like image 36
Reno Avatar answered Oct 21 '22 13:10

Reno