方案主机不工作在Android棒棒糖,点击链接打开应用程序 [英] scheme host not working on android lollipop, click on link to open app

查看:444
本文介绍了方案主机不工作在Android棒棒糖,点击链接打开应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的这块code从一个链接启动我的应用程序。

I am using this piece of code to launch my app from a link.

<activity
        android:name="com.example.myApp.myClass"
        android:label="@string/app_name" >
    <intent-filter>
        <data
            android:host="customHostName"
            android:scheme="customScheme" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>  

这是HREF链接,我想在最后的关键。

This is href link, i want to get the key in the end.

customScheme://customHost/49FYTJTF00

这是工作的罚款Android上的所有previous版本,但不工作的棒棒糖。
当我点击链接,只显示了浏览器的启动列表中。

It is working fine on all previous versions of android, but is not working on Lollipop.
When I click the link it only shows the list of browsers to launch.

我应该怎么办?

推荐答案

您可能,如果这个工程检查 请使用 &LT;意向滤光器&gt; &lt;数据&GT; 元素。例如,要处理到twitter.com所有链接,你把这个在你的&LT;活性GT; 的Andr​​oidManifest.xml

you may check if this works Use an <intent-filter> with a <data> element. For example, to handle all links to twitter.com, you'd put this inside your <activity> in your AndroidManifest.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棒棒糖,点击链接打开应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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