[英]Android - Share browser url to app
I am writing an app for a community, which has the ability to share URLs. 我正在为社区编写一个应用程序,它可以共享URL。
In the android browser, there is the possibility to forward URLs, for example from my HTC Desire to a BlueTooth Target, to Facebook, to Friend Stream, to Google Mail, to Google+, Mail, SMS and Peep. 在Android浏览器中,有可能将URL转发,例如从我的HTC Desire转发到BlueTooth Target,到Facebook,到Friend Stream,到Google Mail,转发到Google+,Mail,SMS和Peep。 What I want to achive is to add my app into that list, providing functionality to forward the current URL from the Browser to the App, regardless on which webpage I am currently.
我想要实现的是将我的应用程序添加到该列表中,提供将当前URL从浏览器转发到应用程序的功能,无论我当前在哪个网页上。
How do I achive that? 我怎么做到这一点?
You do this with intent-filter , with the action SEND . 您可以使用intent-filter执行此操作,并执行SEND操作。 This filter will take plain texts, images and videos.
此过滤器将采用纯文本,图像和视频。
<activity android:name="MyActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
In your activity you can check getIntent().getAction().equals(Intent.ACTION_SEND)
to know you have been started as a send action and getIntent().getType()
what type of data you got. 在您的活动中,您可以检查
getIntent().getAction().equals(Intent.ACTION_SEND)
以了解您已作为发送操作启动并获取getIntent().getType()
您获得的数据类型。
The data itself (Text, image or anything else) can be found via getIntent().getExtras().get(Intent.EXTRA_STREAM)
or getIntent().getStringExtra(Intent.EXTRA_TEXT)
(Depends on data type and the sending application). 数据本身(文本,图像或其他任何东西)可以通过
getIntent().getExtras().get(Intent.EXTRA_STREAM)
或getIntent().getStringExtra(Intent.EXTRA_TEXT)
(取决于数据类型和发送应用程序)找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.