iTu*_*rki 2 android intentfilter android-intent
我的应用程序正在注册接收URL的意图,因此当用户共享网址时,我的应用程序将位于应用列表中.
<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>
Run Code Online (Sandbox Code Playgroud)
-
在我的MainActivity的onCreate()方法中:
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
}
Run Code Online (Sandbox Code Playgroud)
-
我得到的问题是:数据为空,这很奇怪.由于此代码与之完美配合ACTION_VIEW.但是,它没有用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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3888 次 |
| 最近记录: |