Issue
Currently there are some devices that doesn't have Google Play (Huawei Devices), is there a way for me to check programmatically if the device doesn't have one? I wanted to use the in-app-update feature: rel="noreferrer">https://developer.android.com/guide/playcore/in-app-updates and check if the device has a Google PlayStore first.
What I have tried so far: using Uri.parse("market://details?id=" + appPackageName)
but you need to start the activity first to confirm it exists? I'd like to know if there are better ways to do it.
Solution
You can check if the package com.android.vending
exists or not
public static boolean isPackageInstalled(String packageName, PackageManager packageManager) {
try {
return packageManager.getApplicationInfo(packageName, 0).enabled;
}
catch (PackageManager.NameNotFoundException e) {
return false;
}
}
And you can do like this in your activity
if(isPackageInstalled("com.android.vending", getPackageManager())){
// play store is installed
}else{
// play store is not installed
}
Answered By - Sujan Poudel
Answer Checked By - Cary Denson (JavaFixing Admin)