Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 760
RakshithAnand Avatar asked Feb 02 '15 04:02

RakshithAnand


1 Answers

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!

like image 178
Sarangan Avatar answered Sep 29 '22 05:09

Sarangan