Kiosk-app重启后仅显示黑屏

时间:2019-04-01 11:35:41

标签: android kiosk kiosk-mode

我正在遵循这两个类似的教程,使用信息亭应用程序创建专用设备: Java Language Specification 9.6.4.4.Tutorial 1。 我设法创建了一个正常运行的应用程序,但是当设备(Android 5.1,API 22)重启时出现了一个问题,我可以看到该应用程序通过记录器在后台运行,但是没有显示主要活动,并且存在只有黑屏。

在两个教程中描述了我所遵循的步骤,关于主要应用程序(称为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>

1 个答案:

答案 0 :(得分:0)

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

mDevicePolicyManager.setKeyguardDisabledFeatures(mAdminComponentName, KEYGUARD_DISABLE_FEATURES_ALL);

可能我正在插入此方法,以替代在教程1中找到的以下行:

mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, true);

因为后一种方法仅适用于API> 23我无法在我的项目上使用,因为目标API是22,所以我认为直接替代是前一种,而我是“阻止”了必要。