Cuper Hector
Cuper Hector

Reputation: 856

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 there is any exception thrown. But I don't think this is a wise approach.

Upvotes: 3

Views: 669

Answers (2)

Sebastian L.
Sebastian L.

Reputation: 11

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);

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006944

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.

Upvotes: 4

Related Questions