How do I receive a “Share URL” from browser?

2020-06-11 09:36发布

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

2条回答
啃猪蹄的小仙女
2楼-- · 2020-06-11 09:59

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);
查看更多
Ridiculous、
3楼-- · 2020-06-11 10:20

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);
查看更多
登录 后发表回答