How to check if an activity is locked (app pinning) in android Lollipop

让人想犯罪 __ 提交于 2019-12-05 01:02:48
Sarangan

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!

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