I need to know if the user is interacting with the device, so I used this following code. I donβt know if itβs normal to use it Build.VERSION.SDK_INTso that it works 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");
}
separated method: isScreenOn()
source
share