Reputation: 33
Android market URLs on the form market://details?id...
can be used to launch the Google Play app, and download other apps.
But when using an Android device which didn't come with the Google Play app, or on which it has been deleted, trying to open a market:// ...
URL results in "unable to load the page".
Is there any way to detect the absence of the Google Play app using javascript, in order to suggest to the user that he/she installs the Google Play app, rather than showing a generic error message?
Sorry,didn't say it clearly, I am using "market://.." url download in a web page,not a native android app,so the answer of Raghav Sood is not what I want,thanks all the same.
Upvotes: 3
Views: 398
Reputation: 82533
You can use this to check if Google Play is installed by attempting to launch it with a dummy intent:
public boolean hasGooglePlayInstalled() {
Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=dummy"));
PackageManager manager = mContext.getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(market, 0);
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).activityInfo.packageName.startsWith("com.android.vending") == true) {
return true;
}
}
}
return false;
}
Just use it in your code as:
if(hasGooglePlayInstalled()) {
//Open Google Play
} else {
//Open browser/show message
}
Upvotes: 2