检查目的URI可用 [英] Check if intent uri is available

查看:125
本文介绍了检查目的URI可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,有时链接到IMDB的应用程序。我可以用 http://m.imdb.com/find 做到这一点,或者如果它是可用 IMDB:///找到。我的问题是我无法找到一个方法来检查是否 IMDB:// 可用之前,为时已晚。

I have an app that sometimes links to imdb. I can do this with http://m.imdb.com/find or if it is available imdb:///find. My trouble is I can't find a way to check whether the imdb:// is available before it is too late.

由于链接被点击的用户,我不能赶上 android.content.ActivityNotFoundException 例外。

Because the link is clicked on by the user, I can't catch the android.content.ActivityNotFoundException exception.

我失去了一些东西明显?

Am I missing something obvious?

解决方法:

通过inazaruk的建议,我现在使用的follwing code:

By inazaruk's suggestion I'm now using the follwing code:

public static boolean isUriAvailable(Context context, String uri) {
    Intent test = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    return context.getPackageManager().resolveActivity(test, 0) != null;
}

该方法必须带一个直接URI来你所要求,如 IMDB:///找到而不仅仅是 IMDB:/ /

推荐答案

您可以使用<一个href="http://developer.android.com/reference/android/content/pm/PackageManager.html#resolveActivity%28android.content.Intent,%20int%29"><$c$c>resolveActivity()检测是否有任何活动系统能够处理你的意图。当然,你需要构造模仿URI点击的意图。这可能使用来完成的<$c$c>Intent.setData()功能,虽然我没有测试/验证自己。

You can use resolveActivity() to detect whether there is any Activity in the system capable of handling your intent. Of course you need to construct the intent that mimics the "uri" click. That might be done using Intent.setData() function, though I didn't test/verify that myself.

这篇关于检查目的URI可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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