Kiosk-app 重启后只显示黑屏

Kiosk-app shows only black screen after reboot

我正在按照这两个类似的教程使用信息亭应用程序创建专用设备: Tutorial 1 and Tutorial 2。 我设法创建了一个可用的应用程序,但是当设备(Android 5.1,API 22)重新启动时出现问题,我可以通过记录器看到该应用程序在后台运行,但主要 activity 没有出现,只有黑屏。

我所遵循的步骤在两个教程中都有描述,我更改最多的代码是以下关于主应用程序(称为 VmLoaderActivity)的代码:

private ComponentName mAdminComponentName = null;
private DevicePolicyManager mDevicePolicyManager = null;
private String thisAppPackageName = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 mAdminComponentName = VmDeviceAdminReceiver.getComponentName(this);
 mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
 thisAppPackageName = getApplicationContext().getPackageName();

 if (mDevicePolicyManager.isDeviceOwnerApp(thisAppPackageName)) {
  setKioskPolicies();
 }
}


private void setKioskPolicies() {
 /*
  * Allow only this package
  */
 String[] allowedPackages = new String[] {
  thisAppPackageName
 };
 mDevicePolicyManager.setLockTaskPackages(mAdminComponentName, allowedPackages);

 /*
  * Set our app as the default application.
  */
 IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MAIN);
 intentFilter.addCategory(Intent.CATEGORY_HOME);
 intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
 mDevicePolicyManager.addPersistentPreferredActivity(mAdminComponentName,
  intentFilter, new ComponentName(thisAppPackageName, VmLoaderActivity.class.getName()));

 /*
  * Disable Keyguard so that when the device boots, our application will start immediately
  * without the lock screen appearing.
  */
 mDevicePolicyManager.setKeyguardDisabledFeatures(mAdminComponentName, KEYGUARD_DISABLE_FEATURES_ALL);
 //mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, true); //for newer APIs

 /*
  * Keep our application awake
  */
 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

 /*
  * Enable our app to be in fullscreen mode.
  */
 int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
  View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
  View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
  View.SYSTEM_UI_FLAG_FULLSCREEN |
  View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
 getWindow().getDecorView().setSystemUiVisibility(uiOptions);

 //Starts the lock task
 startLockTask();
}

此外,这是清单的相关部分:

   <activity
            android:name="VmLoaderActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
   </activity>

我已通过删除以下行解决了问题:

mDevicePolicyManager.setKeyguardDisabledFeatures(mAdminComponentName, KEYGUARD_DISABLE_FEATURES_ALL);

可能我插入了这个方法来代替教程 1 中的以下行:

mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, true);

因为后一种方法只适用于>23的API我的项目无法使用因为目标API是22的所以我一直在想直接替代是前一种,而不是我是"blocking" 必要的东西。