How could I write a code which can tell me that android market is installed on your android phone?
Asked
Active
Viewed 3,040 times
2 Answers
8
There are two ways. You can use the already mentioned getPackageManager()
and getApplicationInfo()
(if the package is not found, a PacketManager.NameNotFoundException
will be thrown - see here). Android Market's package name is com.android.vending
.
However, you can also create a dummy intent for searching the market and check how it is handled. If the resulting list has at least one entry, you can be sure that Android Market is installed:
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=dummy"));
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(mmarket, 0);
-
Is "com.android.vending" also the packageName on Honeycomb (or later) devices where the "MyApps" application is used? Also, the "market://" intent check is unreliable because other market apps also use that. – Mark Nov 11 '11 at 04:08
-
I cannot say for sure when it comes to com.android.vending and Honeycomb. However, Android Developers refer to com.android.vending without any Honeycomb-specific notes (e.g.: http://developer.android.com/guide/publishing/licensing.html), so I'd assume it works as expected. – Nov 11 '11 at 15:12
-
1On the Kindle Fire, Amazon's App Store will response to the market:// URIs. – Brian Pellin Jan 10 '12 at 21:55
-
@BrianPellin Do u mean that when I pass the intent with market:// URI, amazon device can still handle it and forward user to Amazon App Store? I know that I cannot upload to Amazon app store if I do so, but what if I don't care about this. – Bear Jun 26 '12 at 01:54
1
Here's what I did (assumes browser exists):
Intent market = new Intent(Intent.ACTION_VIEW).setData(Uri
.parse("market://details?id=com.example.app"));
Intent website = new Intent(Intent.ACTION_VIEW).setData(Uri
.parse("http://play.google.com/store/apps/details?id=com.example.app"));
try {
startActivity(market);
} catch (ActivityNotFoundException e) {
startActivity(website);
}

torger
- 2,308
- 4
- 28
- 35