How to check if an activity is locked (app pinning

2020-08-13 05:38发布

I would like to know whether an activity is locked under app pinning in android 5.0 and above programatically. Please help me in this!

Thanks!

1条回答
ゆ 、 Hurt°
2楼-- · 2020-08-13 06:13

Method to get if the activity in lock task mode.
activityManager.isInLockTaskMode() API is deprecated in API level 23. Use the method activityManager.getLockTaskModeState() http://developer.android.com/reference/android/app/ActivityManager.html#getLockTaskModeState()

public boolean isAppInLockTaskMode() {
    ActivityManager activityManager;

    activityManager = (ActivityManager)
        this.getSystemService(Context.ACTIVITY_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // For SDK version 23 and above.
        return activityManager.getLockTaskModeState()
            != ActivityManager.LOCK_TASK_MODE_NONE; 
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // When SDK version >= 21. This API is deprecated in 23.
        return activityManager.isInLockTaskMode();
    }

    return false;
}

Hope this helps you!

查看更多
登录 后发表回答