QR Code provisioning

mirkopinna
New member

Hi,

I created an Android application that has to run on a fully managed device.
I have to make it the only application installed on a device and running on a Kiosk Mode.
I tried provisioning the device using QR Code, to do it I do the following:

 

Created an activity extending DeviceAdminReceiver.

 

 

 

import android.app.admin.DeviceAdminReceiver

class AdminReceiver : DeviceAdminReceiver()

 

 

 

 

Added it into the manifest:

 

 

 

     <receiver
            android:name=".kioskmode.AdminReceiver"
            android:exported="true"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin" />

            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>
        </receiver>

 

 

 

 

Created activity to handle ADMIN_POLICY_COMPLIANCE and GET_PROVISIONING_MODE:

 

 

 

<activity
            android:exported="true"
            android:name=".dpc.AdminPolicyComplianceActivity"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <intent-filter>
                <action android:name="android.app.action.ADMIN_POLICY_COMPLIANCE"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:exported="true"
            android:name=".dpc.ProvisioningModeActivity"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <intent-filter>
                <action android:name="android.app.action.GET_PROVISIONING_MODE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

 

 

 

 

 

 

 

class AdminPolicyComplianceActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setResult(RESULT_OK, resultIntent)
        finish()
    }
}

 

 

 

 

 

 

 

class ProvisioningModeActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val resultIntent = Intent()
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            resultIntent.putExtra(DevicePolicyManager.EXTRA_PROVISIONING_MODE, 
            DevicePolicyManager.PROVISIONING_MODE_FULLY_MANAGED_DEVICE)
        }
        setResult(RESULT_OK)
        finish()
    }
}

 

 

 

 

I created the QR code using the codelab and edited the code to the following:

 

 

 

 

{
    "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "com.myapp/com.myapp.kioskmode.AdminReceiver",
    "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://www.dropbox.com/scl/xxxxx",
    "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "xxxxxxx",
    "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED": true,
    "android.app.extra.PROVISIONING_WIFI_SSID": "xxxxx",
    "android.app.extra.PROVISIONING_WIFI_HIDDEN": false,
    "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE": "WPA",
    "android.app.extra.PROVISIONING_WIFI_PASSWORD": "xxxxxxx",
    "android.app.extra.PROVISIONING_SKIP_ENCRYPTION": false,
    "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE":
    {
        "com.google.android.apps.work.clouddpc.EXTRA_ENROLLMENT_TOKEN": "xxxxxx"
    }
}

 

 

 

 

but I always get the error "Can't set up device. Contact your IT admin for help"

 

If I try to provision the app using this qr code https://github.com/googlesamples/android-testdpc/tree/master

it works well on the same device.

Is there anything that I am missing?

 

Regards.

0 REPLIES 0