我有一个应用程序将自己注册为默认启动器,并在启动时自动固定自己。
安装应用程序时,这一切都很好。它固定自己,只有后退按钮可见。
问题是当设备第一次启动时,它没有正确固定。我多次看到一系列“屏幕固定”和“屏幕未固定”的祝酒词。“主页”和“最近的任务”按钮仍然可见。
--
运行“adb shell dumpsys activity activities”——最后几行表明它没有被固定:
mLockTaskModeState=NONE mLockTaskPackages (userId:packages)=
0:[com.example.myapp]
mLockTaskModeTasks[]
--
运行 Marshmallow/6.0/23 的测试设备 Asus ZenPad
我依靠 MainActivity 清单属性“lockTaskMode”来固定(而不是 activity.startLockTask()):
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/launcher_main"
android:launchMode="singleTask"
android:lockTaskMode="if_whitelisted"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
任何帮助或指示将不胜感激