Android的 - 共享浏览器的URL应用程序 [英] Android - Share browser url to app

查看:194
本文介绍了Android的 - 共享浏览器的URL应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个应用程序的一个社区,它具有共享的URL的能力。

I am writing an app for a community, which has the ability to share URLs.

在Android浏览器,还有就是从我的HTC Desire到蓝牙目标,Facebook的,到了Friend Stream,以谷歌邮件,到Google+,邮件,短信和窥视转发URL,例如可能性。我想才达到是增加我的应用程序进入该名单,提供的功能,从浏览器到应用程序转发当前的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. 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.

我如何achive呢?

How do I achive that?

推荐答案

为此,您可以意图-filter ,一起行动的发送的。该过滤器将明码文,图片和视频。

You do this with intent-filter, with the action 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>

在你的活动,你可以检查 getIntent()的getAction()。等于(Intent.ACTION_SEND)来知道你已经开始作为一个发送动作和 getIntent()的getType()你有什么类型的数据。

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()找到。getExtras()。得到(Intent.EXTRA_STREAM) getIntent()。getStringExtra(Intent.EXTRA_TEXT)(取决于数据类型和发送应用程序)。

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).

这篇关于Android的 - 共享浏览器的URL应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆