4

I am building an Android KIOSK app, and I try to enable kiosk mode with Android Management API by providing a device policy.

My policy json is:

    {
        "keyguardDisabled": true,
        "applications": [
                {
                  "packageName": "my.own.app",
                  "installType": "KIOSK",
                  "defaultPermissionPolicy": "GRANT"
                }
        ]
    }

What's interesting, the policy is from official API's example, so I suppose that works. Whatever, always get this error:

Error info persistentPreferredActivities 4

And just a google search does not give me any clue how to resolve this.

When I set installType as KIOSK, I always got this error. My clue was that my policy lacks of PersistentPreferredActivity json block. I've added it, and I still got this error. What's interesting, there's a note: "Note: To set up a kiosk, use InstallType to KIOSK rather than use persistent preferred activities." So we do not need PersistentPreferredActivity. But I do not understand the error then.

Moving on. I've tried to make kiosk mode by setting kioskCustomLauncherEnabled to true. I set "installType": "AVAILABLE", so I can run the app from Android Studio. I applied the policy on a device successfully. When I try to open my app's Kiosk Activity I have "App is not device owner" Toast.

Basically, what I need is probably lockTaskAllowed modifier, but it's deprecated.

Could somebody help me to make the device policy for KIOSK app, please?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Oleksandr Nos
  • 332
  • 5
  • 17
  • hi, have you figured out this / how to make the `KIOSK` policy works? Thanks! – H.T. Koo Jun 08 '20 at 06:06
  • Just FYI I had [solved my error by adding some `intent-filter` for the `MainActivity`](https://stackoverflow.com/a/62275564/10734272) – H.T. Koo Jun 09 '20 at 05:23

2 Answers2

4

Take note that KIOSK mode only works on fully managed devices. For a device to be fully managed, it must be provisioned from a setup wizard by using QR code containing an enrollment token or by other supported enrollment methods.

To be able to use the app in a policy, it must be available in Google Play. It should either be a public app or a private app that is made available to the enterprise (ID) you are managing with the Android Management API.

Here's the difference between "installType": "KIOSK" and kioskCustomLauncherEnabled:

"installType": "KIOSK" is used to pin a single app to the screen

policy_json = '''
{
  "applications": [
  {
    "packageName": "com.google.android.gm",
    "installType": "KIOSK",
    "defaultPermissionPolicy": "GRANT"
  }
],
  "debuggingFeaturesAllowed": true
}
'''

Now, if you want to use a set of apps in KIOSK mode you can use kioskCustomLauncherEnabled

policy_json = '''
{
  "applications": [
    {
    "packageName": "com.android.chrome",
    "installType": "FORCE_INSTALLED",
    "defaultPermissionPolicy": "GRANT"
  },
  {
    "packageName": "com.google.android.gm",
    "installType": "FORCE_INSTALLED",
    "defaultPermissionPolicy": "GRANT"
  }
],
  "debuggingFeaturesAllowed": true,
  "kioskCustomLauncherEnabled": true,
  "keyguardDisabled": true
}
'''
Dave Paurillo
  • 231
  • 1
  • 12
1

FWIW, I had encountered the same Error info persistentPreferredActivities 4 error and I had solved my error by adding <category android:name="android.intent.category.HOME"/> and <category android:name="android.intent.category.DEFAULT"/> for my MainActivity

And my AndroidManifest.xml looks something like this now:

    ...
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
                <category android:name="android.intent.category.HOME"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
    ...

(Disclaimer: Hope this can help eliminating the error but I am quite new to Android development works so this might not be able to solve every problems)

H.T. Koo
  • 120
  • 4
  • 9