如何从ACTION_SEND获得网址是什么? [英] how to get URL from ACTION_SEND?
本文介绍了如何从ACTION_SEND获得网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序注册一个意图接收网址所以当用户共享一个网址,我的应用程序将在应用程序列表。
My app is registering an intent to receive URLs so when the user shares a url, my app will be in the list of apps.
<intent-filter
android:label="my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
-
在我MainActivity的onCreate()方法:
in my MainActivity's onCreate() method:
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_SEND)) {
Uri data = intent.getData();
String s = data.toString();
output.setText(s); //output: a TextView that holds the URL
}
-
我的问题是:数据为空这是奇怪的。由于这code。与 ACTION_VIEW
完美的作品。然而,它并没有与 ACTION_SEND
工作。
The problem I got is: data is null which is strange. Since this code works perfectly with ACTION_VIEW
. However, it didn't work with ACTION_SEND
.
我怎么可以修改它的工作?
推荐答案
您可以尝试
String action = intent.getAction();
if (action.equalsIgnoreCase(Intent.ACTION_SEND) && intent.hasExtra(Intent.EXTRA_TEXT)) {
String s = intent.getStringExtra(Intent.EXTRA_TEXT);
output.setText(s); //output: a TextView that holds the URL
}
这篇关于如何从ACTION_SEND获得网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文