Skip to content

Instantly share code, notes, and snippets.

@bashenk
Last active June 28, 2026 17:54
Show Gist options
  • Select an option

  • Save bashenk/58c6dd883b177ee6e6ed1c533f3e8066 to your computer and use it in GitHub Desktop.

Select an option

Save bashenk/58c6dd883b177ee6e6ed1c533f3e8066 to your computer and use it in GitHub Desktop.
Creating a QR Code for Android Device Enrollment

Creating a QR Code for Android Device Enrollment

Android Enterprise Documentation: Create a QR code

Always required

Required if a DPC isn't already installed on the device

Recommended if the device isn't already connected to Wi-Fi

Optional


EMM Provisioning

Android Zero-Touch Enrollment EMM Provisioning Guide

👍 EMM Recommended

Use the following intent extras to set up your DPC

👎 EMM Not recommended

Don't include the following extras that you might use in other enrollment methods


Additional references

@MichaelTeeuw

Copy link
Copy Markdown

I apologies for using this Gist for asking this question, but does anybody happen to have a super barebones DPC kotlin application I can take a look at? I've been working on my own but unfortunately I'm unable to correctly use it using the QR method. After scanning the code, the app is being downloaded, android displays “Device belongs to your organization”, but then it fails. Debugging by fetching the logs is a PITA, but it looks like Android is trying to fall back on the (non existent) CloudDPC app in stead of using my app as the DPC.

Unable to start service Intent { cmp=com.android.managedprovisioning/com.google.android.apps.work.clouddpc.base.managedprovisioning.provisioning.ProvisioningService } U=0: not found

I've got the feeling my app is not correctly registering itself as a DPC app. Any help is highly appreciated!

@MichaelTeeuw

Copy link
Copy Markdown

Finally found it! For anyone running into the same issue; you need the following additional activities (next to your DeviceAdminReceiver):

        <activity
            android:name=".GetProvisioningModeActivity"
            android:exported="true"
            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>

        <activity
            android:name=".PolicyComplianceActivity"
            android:exported="true"
            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>
class PolicyComplianceActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Do any required setup
        val intent = Intent(this, MainActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        startActivity(intent)
        finish()
    }
}
class GetProvisioningModeActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val result = Intent().apply {
            putExtra(
                DevicePolicyManager.EXTRA_PROVISIONING_MODE,
                DevicePolicyManager.PROVISIONING_MODE_FULLY_MANAGED_DEVICE
            )
        }

        setResult(Activity.RESULT_OK, result)
        finish()
    }
}

@Nickztar

Copy link
Copy Markdown

Hi! This has been super helpful. But I am struggling to read the android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE, anyone have any examples or tips on how to get the values out of this? It seems that is supposed to be read from GetProvisioning or PolicyCompliance but am unable to. Any help would be really appricated

@saifikram969

saifikram969 commented Dec 9, 2025

Copy link
Copy Markdown

WhatsApp Image 2025-12-09 at 14 10 27_fbe34e5b

@robin-thoni @bashenk
Device Policy Controller (DPC) QR Provisioning Issue
I am developing a custom Device Policy Controller and attempting to enroll it through QR code provisioning. Below is a detailed description of my implementation and the issue I am facing.
Current DPC Implementation
My DPC application includes the following components and functionality:

Device admin receiver extending DeviceAdminReceiver class (MyDeviceAdminReceiver)
Policy management through DevicePolicyManager API
User interface controls for:

Camera enable/disable functionality
Device lock capability

Remote command execution via Firebase for camera control, device lock, and location tracking
All features function correctly when the app is installed manually and device owner mode is activated through ADB
Successful ADB Provisioning
The following ADB command successfully establishes device owner mode:
adb shell dpm set-device-owner com.example.testemmjc/.MyDeviceAdminReceiver

After executing this command, all policy enforcement features (camera disable/enable, device lock, location tracking) work as intended, confirming that the DPC implementation itself is functional.
Problem Statement
QR code provisioning consistently fails on a factory-reset Samsung device. The error message displayed is:
"Couldn't set up device. Contact your IT admin."
QR Code Configuration
The JSON configuration being used for QR provisioning is:

{
  "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "com.example.testemmjc/.MyDeviceAdminReceiver",
  "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://maharanidevi.com/dpc.apk",
  "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM": "8ldAbIR-Baxlqwv-yUShimRmGyZR8Mqj4vQbI1mFmKo"
}

Verification Steps Completed
I have confirmed the following:

APK is properly signed using release keystore
SHA-256 checksum is correctly calculated and encoded in base64url format
Package name in JSON matches the manifest declaration (com.example.testemmjc)
APK download URL is publicly accessible and serves the correct file
Device has been factory reset with no Google accounts configured
Manual installation combined with ADB device owner activation works without issues
The provisioning process fails during the initial QR scan phase, before the APK installation begins.
Request for Assistance
I am seeking guidance on potential issues related to:

Samsung-specific provisioning requirements or limitations
Differences between APK checksum and signature checksum verification
Server configuration or HTTP headers required for APK hosting
Additional manifest permissions or metadata required specifically for QR provisioning
Android version-specific restrictions (testing on Android 11 or later)
I have followed the official Android Enterprise provisioning documentation, but the QR provisioning method continues to fail while ADB provisioning succeeds with the same DPC application. Any insights into what might be preventing successful QR provisioning would be helpful.

@LAKSHAYNE

Copy link
Copy Markdown

I dont think you can qr provision now . That now requires you to be a google parter or something for emm.

@Nickztar

Copy link
Copy Markdown

It does work, but it is super annoying to figure out why it doesnt work.

@saifikram969 I think your issue is android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME. It for some reason needs to include the full name so yours would be: com.example.testemmjc/com.example.testemmjc.MyDeviceAdminReceiver

@SahilSonar

Copy link
Copy Markdown

Was anyone able to figure this out yet? I have component name as full name but still fails.

@MichMich

Copy link
Copy Markdown

@SahilSonar what are you trying to do? And what are you running into? I’m using QR provisioning without any issues.

@SahilSonar

Copy link
Copy Markdown

@MichMich I am working on a custom DPC. I can set it up through adb fine but post downloading it lands on "Something went wrong" and prompts for a reset :/

@MichMich

Copy link
Copy Markdown

It’s been a while. But I recall having that issue as well. If I recall correctly, it had something to do with missing methods (mentioned earlier in these gist comments).

@SahilSonar

Copy link
Copy Markdown

I am getting INSTALL_FAILED_VERIFICATION_FAILURE my app was also registered for Android developer verification.

@MichMich

Copy link
Copy Markdown

If you install via a QR, you need to give a checksum. Are you sure you’re using the correct checksum?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment