簡體   English   中英

“無法設置設備 - 無法安裝管理應用程序”- 配置設備所有者應用程序的 QR 碼時出錯

[英]"Can't setup device- Couldn't install the admin app"- Error while QR code provisioning of a Device Owner app

我已經創建了一個設備所有者應用程序,但我無法在真實設備上安裝它。 我正在使用這里給出的二維碼方法。

我用來創建二維碼的文字是

{

"android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME":
"com.example.killapplication/com.example.killapplication.DevAdminReceiver",

"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM":
"JdySYN-hMYsxWKagMxbk5q8Giu4lCCsUpQayMMKpwK0",

"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION":
"https://drive.google.com/u/0/uc?id=13O35_iCUcHVqNcuOvnRM5-sc8G586Xgf&export=download",
   
"android.app.extra.PROVISIONING_TIME_ZONE":
"America/Los_Angeles",

"android.app.extra.PROVISIONING_SKIP_ENCRYPTION": false,

"android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE": {
}

}

我通過這樣做從 Android 工作室生成我的 apk:構建 -> 生成簽名的 Apk -> 創建一個新的密鑰庫 -> 確定 -> 下一步 -> Select“發布” -> 構建。 然后我使用創建 package 校驗和

cat /mnt/c/Users/Antarpuneet/app-release.apk | openssl dgst-二進制-sha256 | openssl base64 | tr '+/' '-_' | tr -d '='

恢復出廠設置后,在歡迎屏幕上點擊 6 次打開 QR 閱讀器應用程序,我掃描代碼,然后將我帶到 WIFI 連接屏幕,我成功連接到 Inte.net。 它說設置設備.. 但返回錯誤無法設置設備 - 無法安裝管理應用程序。 這是我的 DevAdminReceiver Class:-

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, "Device Owner Enabled")
        Toast.makeText(context, "Device Owner Enabled", Toast.LENGTH_SHORT).show();
    }


   companion object {
        fun getComponentName(context: Context): ComponentName {

            return ComponentName(context.applicationContext, DevAdminReceiver::class.java)
        }
    }


}

我的主要活動:-

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("com.example.killapplication")) {
            Toast.makeText(this, "YES", Toast.LENGTH_SHORT).show()
            Log.i("Status", "Yes")
        } else {
            Toast.makeText(this, "NO", Toast.LENGTH_SHORT).show()
            Log.i("Status", "No")
        }

        //devicePolicyManager.reboot( mAdminComponentName)
    }



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

    }
}

目前,該應用程序並沒有做太多事情,它只根據是否已向該應用程序授予設備所有者權限來提示“是”或“否”。

我的清單文件:-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.killapplication">


    <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
        tools:ignore="ProtectedPermissions" />
    <uses-permission android:name="android.permission.RESTART_PACKAGES" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <permission android:name="android.permission.REBOOT"/>

    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />



    <application
        android:allowBackup="true"
        android:sharedUserId="android.uid.system"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:testOnly="true">

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver
            android:name=".DevAdminReceiver"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_DEVICE_ADMIN" >
            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>

            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_admin" />
        </receiver>
    </application>

</manifest>

device_admin.xml:-

<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-policies>
        <limit-password />
        <watch-login />
        <reset-password />
        <force-lock />
        <wipe-data />
        <expire-password />
        <encrypted-storage />
        <disable-camera />
        <disable-keyguard-features />
    </uses-policies>
</device-admin>

我已經嘗試過的:

  1. 使用 adb shell 命令在模擬器上安裝應用程序

adb shell dpm set-device-owner com.example.killapplication/.DevAdminReceiver

它成功地將應用程序設置為設備所有者。

  1. 使用上面的 adb 命令在真實設備上安裝應用程序(恢復出廠設置並跳過登錄頁面后)。 它成功地將應用程序設置為設備所有者。 我認為這意味着問題出在二維碼上。

3.使用: android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM而不是android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM ,它返回相同的錯誤。

我正在嘗試將它安裝在帶有 Android 版本 9 的設備上。

更新:我發現“android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION”不接受谷歌驅動器鏈接(或長鏈接),我的應用程序甚至沒有被下載。 所以,我現在已經在一個免費的文件托管網站上托管了我的應用程序,現在正在下載它(我可以從該網站確認)。此外,校驗和沒有問題,因為我嘗試給它錯誤的校驗和,但它返回了校驗和錯誤。 現在,正在下載我的應用程序,但在安裝時,它顯示Blocked by Play Protect並且當我點擊Install Anyway時,它返回舊錯誤:無法設置設備 - 無法安裝管理應用程序

經過多次恢復出廠設置后,我能夠解決我的問題。 首先,確保您在二維碼中提供的鏈接指向此屬性“android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION”

不應是谷歌驅動器鏈接。 為了進行測試,您可以將您的應用程序托管在一個文件托管免費網站上,該網站會為您提供一個短鏈接。

這樣做之后,我的應用程序下載成功但仍然無法安裝。 我發現了問題,這是我的清單中的android:testOnly="true"屬性。 我將它設置為false並且它工作正常。 不過很奇怪,因為我閱讀的所有幫助我創建此設備所有者應用程序的博客都特別要求此屬性為真。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM