title: "Can't setup device- Couldn't install the admin app"- Error while QR code provisioning of a Device Owner app
body: <p>I have created a device owner app but I am having trouble installing it on a real device. I'm using the QR Code method given <a href="https://developers.google.com/android/work/play/emm-api/prov-devices#qr_code_method" rel="nofollow noreferrer">here</a>.</p>
  <p>The text I am using to create my QR Code is</p>
  <pre><code>{
  
  &quot;android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME&quot;:
  &quot;com.example.killapplication/com.example.killapplication.DevAdminReceiver&quot;,
  
  &quot;android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM&quot;:
  &quot;JdySYN-hMYsxWKagMxbk5q8Giu4lCCsUpQayMMKpwK0&quot;,
  
  &quot;android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION&quot;:
  &quot;https://drive.google.com/u/0/uc?id=13O35_iCUcHVqNcuOvnRM5-sc8G586Xgf&amp;export=download&quot;,
     
  &quot;android.app.extra.PROVISIONING_TIME_ZONE&quot;:
  &quot;America/Los_Angeles&quot;,
  
  &quot;android.app.extra.PROVISIONING_SKIP_ENCRYPTION&quot;: false,
  
  &quot;android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE&quot;: {
  }
  
  }
  </code></pre>
  <p>I generate my apk from Android studio by doing this: Build -&gt; Generate Signed Apk-&gt; Create a new keystore -&gt; Ok -&gt; Next-&gt; Select &quot;Release&quot;-&gt; Build.
  Then I create the package checksum using</p>
  <blockquote>
  <p>cat /mnt/c/Users/Antarpuneet/app-release.apk | openssl dgst -binary
  -sha256 | openssl base64 | tr '+/' '-_' | tr -d '='</p>
  </blockquote>
  <p>After doing a factory reset, tapping 6 times on the welcome screen opens a QR reader app, I scan the code and then It takes me to the WIFI connection screen, I successfully connect to the Internet. It says Setting up device.. but returns with the Error <strong>Can't setup device- Couldn't install the admin app.</strong>
  This is my DevAdminReceiver Class :-</p>
  <pre><code>package com.example.killapplication
  
  import android.app.admin.DeviceAdminReceiver
  import android.content.ComponentName
  import android.content.ContentValues.TAG
  import android.content.Context
  import android.content.Intent
  import android.util.Log
  import android.widget.Toast
  
  class DevAdminReceiver: DeviceAdminReceiver() {
  
      override fun onEnabled(context: Context?, intent: Intent?) {
          super.onEnabled(context, intent)
          Log.d(TAG, &quot;Device Owner Enabled&quot;)
          Toast.makeText(context, &quot;Device Owner Enabled&quot;, Toast.LENGTH_SHORT).show();
      }
  
  
     companion object {
          fun getComponentName(context: Context): ComponentName {
  
              return ComponentName(context.applicationContext, DevAdminReceiver::class.java)
          }
      }
  
  
  }
  </code></pre>
  <p>My Main Activity:-</p>
  <pre><code>package com.example.killapplication
  
  import android.Manifest
  import android.app.admin.DevicePolicyManager
  import android.content.ComponentName
  import android.content.Context
  import android.content.pm.PackageManager
  import android.os.Build
  import android.os.Bundle
  import android.util.Log
  import android.view.View
  import android.widget.Button
  import android.widget.Toast
  import androidx.annotation.RequiresApi
  import androidx.appcompat.app.AppCompatActivity
  import androidx.core.app.ActivityCompat
  import androidx.core.content.ContextCompat
  
  class MainActivity : AppCompatActivity() {
      var button: Button? = null
      private lateinit var mAdminComponentName: ComponentName
  
  
      fun onClick(view: View?) {
  
          mAdminComponentName = DevAdminReceiver.getComponentName(this)
          val devicePolicyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
  
          if (devicePolicyManager.isDeviceOwnerApp(&quot;com.example.killapplication&quot;)) {
              Toast.makeText(this, &quot;YES&quot;, Toast.LENGTH_SHORT).show()
              Log.i(&quot;Status&quot;, &quot;Yes&quot;)
          } else {
              Toast.makeText(this, &quot;NO&quot;, Toast.LENGTH_SHORT).show()
              Log.i(&quot;Status&quot;, &quot;No&quot;)
          }
  
          //devicePolicyManager.reboot( mAdminComponentName)
      }
  
  
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
      }
  }
  </code></pre>
  <p>At the moment, the app doesn't do much and only gives a toast <em>Yes or No</em> depending on whether the device owner privilege has been granted to the app or not.</p>
  <p>My Manifest file:-</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      package=&quot;com.example.killapplication&quot;&gt;
  
  
      &lt;uses-permission android:name=&quot;android.permission.READ_PRIVILEGED_PHONE_STATE&quot;
          tools:ignore=&quot;ProtectedPermissions&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.RESTART_PACKAGES&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;
      &lt;permission android:name=&quot;android.permission.REBOOT&quot;/&gt;
  
      &lt;uses-permission android:name=&quot;android.permission.KILL_BACKGROUND_PROCESSES&quot; /&gt;
  
  
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:sharedUserId=&quot;android.uid.system&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/AppTheme&quot;
          android:testOnly=&quot;true&quot;&gt;
  
          &lt;activity android:name=&quot;.MainActivity&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;receiver
              android:name=&quot;.DevAdminReceiver&quot;
              android:label=&quot;@string/app_name&quot;
              android:permission=&quot;android.permission.BIND_DEVICE_ADMIN&quot; &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.app.action.DEVICE_ADMIN_ENABLED&quot; /&gt;
              &lt;/intent-filter&gt;
  
              &lt;meta-data
                  android:name=&quot;android.app.device_admin&quot;
                  android:resource=&quot;@xml/device_admin&quot; /&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p>device_admin.xml :-</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;device-admin xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;uses-policies&gt;
          &lt;limit-password /&gt;
          &lt;watch-login /&gt;
          &lt;reset-password /&gt;
          &lt;force-lock /&gt;
          &lt;wipe-data /&gt;
          &lt;expire-password /&gt;
          &lt;encrypted-storage /&gt;
          &lt;disable-camera /&gt;
          &lt;disable-keyguard-features /&gt;
      &lt;/uses-policies&gt;
  &lt;/device-admin&gt;
  </code></pre>
  <p>What I have already tried:</p>
  <ol>
  <li>Installing the app on an Emulator using the adb shell command</li>
  </ol>
  <blockquote>
  <p>adb shell dpm set-device-owner
  com.example.killapplication/.DevAdminReceiver</p>
  </blockquote>
  <p>It successfully sets the app as a Device owner.</p>
  <ol start="2">
  <li>Installing the app on a real device(after factory reset and skipping sign in
  page) using the adb command above.
  It successfully sets up the app as device owner. I think this means that the
  problem is with the <strong>QR-Code.</strong></li>
  </ol>
  <p>3.Used :
  <em>android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM</em> instead of
  <em>android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM</em> ,
  It returns the same error.</p>
  <p>I am trying to install it on a device with Android Version 9.</p>
  <p>UPDATE: I figured out that <em>&quot;android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION&quot;</em>
  doesn't accept google drive links(or Long links) and my app wasn't even being downloaded. So, I have now hosted my app on a free file hosting website and now it's being downloaded(I can confirm from that website)..Also, there is no problem with the checksum because I tried giving it the wrong ones and it returned with
  a checksum error.
  Now, My app is being downloaded but while installing, it says <strong>Blocked by Play Protect</strong> and when I tap on <em>Install Anyway</em>, it returns with the old error:
  <strong>Can't set up  device - Couldn't install the admin app</strong></p>