App does not work on android 5.0, but on android 7.0

2

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)));
    }
    
asked by givillan 30.11.2018 в 22:46
source

1 answer

0

I think it may be an error found in the Gradle Scripts

The minimum and maximum versions of the sdk are defined in the build.gradle file

The higher your version, the more features you will have, but the fewer devices can install it and vice versa. Check which version of sdk uses android 5.0 and put it in the build.gradle

    
answered by 01.12.2018 в 08:33