开发者

How to detect the existence of Android Market on devices?

Some Android devices don't have Android Market, like Korea, etc.

Is it possible to detect the existence of Android Market at runtime?

I know I can try to open a market uri first to see if开发者_如何学JAVA there is any exception thrown. But I don't think this is a wise approach.


I know I can try to open a market uri first to see if there is any exception thrown.

Create the ACTION_VIEW Intent for the Market Uri, then use PackageManager and queryIntentActivities() to see if you get anything back. If that returns an empty list, you know nothing on the device handles Market Uri values.


A complete solution, that also reads the packagename by itself ...

Context context = this;
final PackageManager packageManager = context.getPackageManager();

String packagename = this.getPackageName();

String url = "market://details?id=" + packagename;

Intent i2 = new Intent(Intent.ACTION_VIEW);
i2.setData(Uri.parse(url));

List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(i2,PackageManager.MATCH_DEFAULT_ONLY);

if (resolveInfo.size() > 0) startActivity(i2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜