Android is screen on or off deprecated isScreenOn()

半腔热情 提交于 2019-12-10 15:16:47

问题


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()

来源:https://stackoverflow.com/questions/30718783/android-is-screen-on-or-off-deprecated-isscreenon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!