启动Android浏览器中的自定义Android应用 [英] Launch custom android application from android browser

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

问题描述

任何人都可以请指导我关于如何从Android浏览器中启动我的Andr​​oid应用程序?

Can anybody please guide me regarding how to launch my android application from the android browser?

推荐答案

使用的<一个href="http://developer.android.com/guide/topics/manifest/intent-filter-element.html"><$c$c><intent-filter>以<一href="http://developer.android.com/guide/topics/manifest/data-element.html"><$c$c><data>元件。例如,要处理到twitter.com所有链接,你把这个在你的&LT;活性GT; 的Andr​​oidManifest.xml

<intent-filter>
    <data android:scheme="http" android:host="twitter.com"/>
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

然后,当用户点击一个链接,浏览器到Twitter,他们将被要求使用,以什么样的应用程序来完成动作:在浏览器或应用程序

Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application.

当然,如果你想为你的网站和你的应用程序之间的紧密集成,您可以定义自己的方案:

Of course, if you want to provide tight integration between your website and your app, you can define your own scheme:

<intent-filter>
    <data android:scheme="my.special.scheme" />
    <action android:name="android.intent.action.VIEW" />
</intent-filter>

然后,在你的web应用程序,你可以把喜欢的链接:

Then, in your web app you can put links like:

<a href="my.special.scheme://other/parameters/here">

当用户点击它,你的应用程序将自动启动(因为它可能会,可以处理 my.special.scheme只有一个:// 键入的URI)。唯一的缺点是,如果用户没有安装该应用程序,他们会得到一个讨厌的错误。而且我不知道有任何的方法来检查。

And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check.

编辑:要回答你的问题,你可以使用 getIntent()的getData()返回一个的 乌里 对象。然后,您可以使用开放的。* 的方法来提取所需的数据。举例来说,假设以点击一个链接,用户 http://twitter.com/status/1234

To answer your question, you can use getIntent().getData() which returns a Uri object. You can then use Uri.* methods to extract the data you need. For example, let's say the user clicked on a link to http://twitter.com/status/1234:

Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"

您可以做上面的任何地方你的活动,但你可能会想这样做的的onCreate()。您也可以使用 params.size()来获得路径段中的乌里的数量。看看到的javadoc或者Android开发者网站,其他乌里方法可用于提取特定部分。

You can do the above anywhere in your Activity, but you're probably going to want to do it in onCreate(). You can also use params.size() to get the number of path segments in the Uri. Look to javadoc or the android developer website for other Uri methods you can use to extract specific parts.

这篇关于启动Android浏览器中的自定义Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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