简体   繁体   中英

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 . 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.

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):

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM