我可以判断用户是否已接受我的活动的屏幕固定请求?

Joe*_*nde 1 android android-5.0-lollipop

我正在阅读新的Android 5.0 Lollipop API(https://developer.android.com/about/versions/android-5.0.html)的概述,我开始对屏幕固定功能感兴趣.

我可以成功请求我的Activity启动屏幕固定,但我不知道用户是否接受了固定请求.startLockTask()方法没有返回值,我没有看到任何回调的提及.

我希望我的活动能够以不同的方式做出反应,具体取决于屏幕是否已成功固定.这有可能还是我的希望有点过高?

谢谢.

Joe*_*nde 5

我实际上刚刚找到了这个问题的答案.

该方法在ActivityManager中,而不是Activity,并且没有从Activity API中进行引用,因此我没有立即看到它.

您可以通过以下代码查看您的活动是否已进入任务锁定模式(或屏幕固定):

 ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
 if (activityManager.isInLockTaskMode())
 {
     // react accordingly
 }
Run Code Online (Sandbox Code Playgroud)