"无活动处理的意图"并非所有的手机都安装了Android电子市场 [英] "no activity found to handle intent" Not all phones have Android Market installed
问题描述
不是所有的手机都安装了安卓市场,因此使用意向的应用程序无法打开市场。
Not all phones have Android Market installed, and therefore using intent to open market app fails.
什么是处理这个问题的最好方法是什么?
What's the best way to handle this?
- 在隐藏这个功能,如果用户没有Android Market的安装(我将如何检测呢?)。
- 处理可能出现的错误,如何(以及可能表明,用户下载Android市场)?
推荐答案
以上回答的问题是,如果你只是传递一个URL,用户将被提示如何处理意向。
The problem with the answer above is that if you just pass a URL the user will be prompted how to handle the Intent.
有一个更优雅的方式来做到这一点IMO,扩充了 href="http://stackoverflow.com/a/8370433/1851478"> 1日的回答,是检验市场是否应用程序安装,然后如果不是,通过一个URL(实际上,你会再想要测试一下,看看有什么东西就可以搞定的意图,但如果你碰巧有一个设备,而无需双方Play商店和浏览器的话,我会问为什么用户将我的应用程序安装在第一位(另外一个故事,我想)......
A more graceful way to do it IMO, expanding upon the 1st answer above, is to test whether the market app is installed, and then if not, pass a URL (which actually you would then want to test to see if something can handle that intent, but if you happen to have a device without both the play store and a browser then I would question why the user would have my app installed in the first place (another story I suppose)....
或许有更好的办法,但这里是我的作品:
Perhaps there is a better way, but here's what works for me:
private String getMarketURI(String marketURL) {
String returnURL = "";
PackageManager packageManager = getApplication().getPackageManager();
Uri marketUri = Uri.parse("market://" + marketURL);
Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(marketUri);
if (marketIntent.resolveActivity(packageManager) != null) {
returnURL = "market://" + marketURL;
} else {
returnURL = "https://play.google.com/store/apps/" + marketURL;
}
return returnURL;
}
,然后使用它像这样:
And then use it like so:
marketIntent.setData(Uri.parse(getMarketURI("details?id=com.yourapps.packagename")));
这篇关于"无活动处理的意图"并非所有的手机都安装了Android电子市场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!