簡體   English   中英

應用已設置為個人資料所有者,但無法再將其刪除

[英]App already set as profile owner, but can't remove it anymore

我有一個類 AdminReceiver 在我的應用程序中擴展 DeviceAdminReceiver。 以前我通過 ADB shell 使它成為配置文件所有者

adb shell dpm set-active-admin com.example.myApp/com.example.myApp.AdminReceiver 
adb shell dpm set-profile-owner com.example.myApp/com.example.myApp.AdminReceiver

一切都很順利。 隨后,我想以編程方式從我的應用程序中執行以下指令將其刪除:

DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
    try {
        dpm.clearProfileOwnerApp(packageName);
    } catch (Exception e) {
        Log.e(TAG, "removingProfile: ", e);
    }

我得到以下異常:

java.lang.SecurityException: Admin ComponentInfo{com.example.myApp/com.example.myApp.AdminReceiver} does not own the profile

.

當我嘗試通過 ADB 再次設置配置文件所有者時,出現以下異常

java.lang.IllegalStateException: Trying to set the profile owner, but profile owner is already set

.

這很瘋狂,因為當我嘗試刪除個人資料所有者時,它就像沒有它一樣,如果我嘗試使它成為個人資料所有者,它就像它已經擁有一樣!

有沒有沒有任何設備恢復出廠設置的解決方案?

正面臨同樣的問題,終於找到了解決方案。

安裝腳本

adb install app.apk
adb shell dpm set-device-owner [your.package]/.DeviceAdminReceiver

卸載腳本

adb install -r -t app-testOnly.apk
adb shell dpm remove-active-admin [your.package]/.DeviceAdminReceiver
adb shell pm uninstall [your.package]

注意:您需要先創建一個testOnly版本的應用程序。 此外,如果實際應用程序已簽名,則 testOnly 必須使用相同的證書進行簽名。

暫無
暫無

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

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