我想知道一个 Activity 是否以编程方式锁定在android 5.0及更高版本中的应用固定下。请帮助我!
谢谢!
最佳答案
获取 Activity 是否处于锁定任务模式的方法。
在API级别23中,不推荐使用activityManager.isInLockTaskMode()API。使用方法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;
}
希望这对您有所帮助!