[英]Kiosk-app shows only black screen after reboot
I am following these two similar tutorials for creating dedicated devices using a kiosk application: Tutorial 1 and Tutorial 2 . 我正在按照这两个类似的教程来使用kiosk应用程序创建专用设备: 教程1和教程2 。 I managed to create a working application, but there is a problem when the device (Android 5.1, API 22) reboots, I can see that the app works in background through the logger, but the main activity doesn't show up and there is only a black screen. 我设法创建了一个有效的应用程序,但是当设备(Android 5.1,API 22)重新启动时出现问题,我可以看到该应用程序通过记录器在后台运行,但主要活动没有显示,并且有只有黑屏。
The steps that I have followed are described in the two tutorials, the code that I have changed the most is the following regarding the main app (called VmLoaderActivity): 我遵循的步骤在两个教程中描述,我更改的代码是关于主应用程序的以下代码(称为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();
}
In addition, this is the relevant section of the manifest: 此外,这是清单的相关部分:
<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>
I have resolved the problem by deleting the following row: 我已通过删除以下行解决了该问题:
mDevicePolicyManager.setKeyguardDisabledFeatures(mAdminComponentName, KEYGUARD_DISABLE_FEATURES_ALL);
Probably I was inserting this method as a substitute of the following row found in the tutorial 1: 可能我插入此方法作为教程1中的以下行的替代:
mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, true);
Because the latter method is only for APIs > 23 I was unable to use on my project because the target APIs are 22, then I was thinking that the direct substitute was the previous one, instead I was "blocking" something that was necessary. 因为后一种方法仅适用于> 23的API,我无法在我的项目上使用,因为目标API是22,然后我认为直接替代是前一个,而是我“阻止”必要的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.