I'm a novice in programming. I'm running an app that detects if an app is installed and open the play store; I found this code How to make the PlayStore open if an app is not installed? and work perfectly on a smartphone with android 7, but on a tablet with android 5.0 it does not work. Please your help or recommendations. Thank you. Code to detect if the application is installed on the device from its packagename, it would be.
public static boolean instaladaAplicacion(String packagename, Context context) {
boolean response = false;
try {
context.getPackageManager().getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
response = true;
} catch (PackageManager.NameNotFoundException e) {
Log.i("Android", "NNFE aplicación no instalada: " + e.getMessage());
}
return response;
}
If you can not find the application, open the play store:
String packageName = "com.example.speedometer";
String MARKET_SQUEME = "market://details?id=";
//Verifica si la aplicación se encuentra instalada.
if(instaladaAplicacion(packageName, getApplicationContext())){
Intent i = getPackageManager().getLaunchIntentForPackage(packageName);
i.addCategory(Intent.CATEGORY_LAUNCHER);
//Abre aplicación.
startActivity(i);
}else{ //No se encuentra instalada.
//Abre aplicación en Playstore
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(MARKET_SQUEME + packageName)));
}