PoYo Rivera
PoYo Rivera

Reputation: 163

Android QR device owner provisioning: how to get EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE from QR?

im trying to get the custom property from ANDMIN_EXTRAS_BUNDLE to be able to do different things accord to this parameter "company_name" but i can´t. i tried to get in in a "PROFILE_PROVISIONING_COMPLETE" receiver but it din´t work

class ProfileProvisioningCompleteReceiver: BroadcastReceiver() {

override fun onReceive(context: Context?, intent: Intent?) {

    Log.d("PROFILE PROVISIONING", "onReceive " + intent!!.action)
    if (ACTION_PROFILE_PROVISIONING_COMPLETE == intent.action) {

        val extras: PersistableBundle? = intent.getParcelableExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE)
        Toast.makeText(context, "onReceive Extras:" + extras!!.getString("company_name"), Toast.LENGTH_LONG).show()
    }
}

}

also i tried to put this same code in two different activities with intents "ADMIN_POLICY_COMPLIANCE" and "GET_PROVISIONING_MODE" as the doc says

my QR json looks like

{ "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "myAdminReceiver", "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "123asddf", "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "download/url", "android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED": true, "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE": { "company_name": "my company" } }

any help would be appreciate

Upvotes: 2

Views: 1698

Answers (1)

Mohsen Abedini
Mohsen Abedini

Reputation: 184

use onProfileProvisioningComplete() method in your DeviceAdminReceiver class.

this method trigger after success provision complete with Qr or Nfc

like this:

class DeviceAdminReceiver : DeviceAdminReceiver() {

    override fun onProfileProvisioningComplete(context: Context, intent: Intent) {
        super.onProfileProvisioningComplete(context, intent)
       
        val extras: PersistableBundle? = 
          intent.getParcelableExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE)
          Toast.makeText(context, "onReceive Extras:" + 
          extras!!.getString("company_name"), Toast.LENGTH_LONG).show()
        }

    override fun onEnabled(context: Context, intent: Intent) {
        super.onEnabled(context, intent)
    }

    override fun onDisabled(context: Context, intent: Intent) {
        Toast.makeText(context, "onDisabled", Toast.LENGTH_SHORT).show()
    }
}

and in manifest file:

<receiver
            android:name=".core.broadcast.DeviceAdminReceiver"
            android:enabled="true"
            android:exported="true"
            android:label="device_admin"
            android:permission="android.permission.BIND_DEVICE_ADMIN">
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin_receiver" />
            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
                <action android:name="android.app.action.PROFILE_PROVISIONING_COMPLETE" />
                <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
                <action android:name="android.app.action.DEVICE_OWNER_CHANGED" />

            </intent-filter>
        </receiver>

remember dont remove super in onProfileProvisioningComplete method

Upvotes: 1

Related Questions