Android 设置系统有无锁屏方式

sancaiodm Android应用 2023-07-07 450 0

设置系统是否有锁屏方式,可直接使用

private void clearScreenLock(boolean state){

    // get QMMI userId
    android.os.UserHandle handle = android.os.Process.myUserHandle();
    int userId = handle.hashCode();

        // get screen lock state: locked or unlocked
    LockPatternUtils utils = new LockPatternUtils(this);

    /* Different type of screen lock has different state:
     * the value of isLockScreenDisable:
     * None: true
     * Swipe, Pattern, PIN, Password: false
     */
    boolean isDisable = utils.isLockScreenDisabled(userId);
    android.util.Log.i(TAG, "isLockScreenDisabled:" + isDisable);

    /* get screen secure state: true or false
     * the value of isSecure:
     * Swipe: false
     * None, Pattern, PIN, Password: true
     */
    boolean isSecure = false;

    try {
        isSecure = utils.getLockSettings().getBoolean(LockPatternUtils.DISABLE_LOCKSCREEN_KEY,false,userId);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    android.util.Log.i(TAG, "isSecure:" + isSecure);
    if ( !isDisable ){
        utils.setLockScreenDisabled(state,userId);//state 为true则设置无锁屏方式, 为false则是设置有锁屏方式(滑动锁屏)
        if (isSecure ){
            //If screen is locked with Pattern, PIN or password, show the warn info
            Toast.makeText(context, "keypad_need_unlock_screen", Toast.LENGTH_LONG).show();
        }
    }//If screen don't locked, pass it.
}


评论