如何从ACTION

编程入门 行业动态 更新时间:2024-10-11 03:23:25
本文介绍了如何从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

本文发布于:2023-11-28 17:42:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ACTION

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!