Android is screen on or off deprecated isScreenOn()

5.4k Views Asked by At

I need to know if user is interacting with device, that's why I used this following code. I dont know if its ok to use Build.VERSION.SDK_INT this way, so that will work on all versions.?

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        if (pm.isInteractive()) {
            System.out.println("alarm screen ON");
        }
    }
    else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH){
        if(pm.isScreenOn()){
            System.out.println("alarm screen ON");
        }
    }

    else {
        System.out.println("alarm screen OFF");
    }

the depracated method is: isScreenOn()

0

There are 0 best solutions below