“当我的应用程序使用设备所有者应用程序的二维码安装时,它显示已被 Play Protect 阻止”

问题描述 投票:0回答:2

enter image description here

我创建了一个设备所有者应用程序,但在真实设备上安装它时遇到问题。我正在使用生成二维码 https://datalogic.github.io/aeqrdoc/generat

我用来创建二维码的文本是

{
  "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "com.example.demo/com.example.demo.DemoAppDeviceAdminReceiver",
  "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "DyseoYKEDCtnYx3jyiHCdLUvZ7F-uFenEe4sZ9bRZYw",
  "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://www.dropbox.com/scl/fi/q6094argfv56z8zd1i589/app-release.apk?rlkey=alt5estnbfj5oqazbrmfm7ppc&dl=1"
}

我通过这样做从 Android studio 生成我的 apk: 构建 -> 生成签名包/Apk -> 选择 APK -> 创建新的密钥库 -> 确定 -> 下一步 -> 选择“发布”-> 构建。然后我使用

创建包校验和
cat /mnt/c/Users/Antarpuneet/app-release.apk | openssl dgst -binary -sha256 | openssl base64 | tr '+/' '-_' | tr -d '='

恢复出厂设置后,在欢迎屏幕上点击 6 次会打开一个 QR 阅读器应用程序,我扫描代码,然后它会将我带到 WIFI 连接屏幕,我成功连接到互联网。它显示正在设置设备..但返回错误无法设置设备 - 无法安装管理应用程序。

这是 DemoAppDeviceAdminReceiver 类:-

package com.example.demo;

import static android.content.ContentValues.TAG;

import android.app.admin.DeviceAdminReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class DemoAppDeviceAdminReceiver extends DeviceAdminReceiver {
    // Optional: Override methods as needed for handling device admin events
    // For example:
    @Override
    public void onEnabled(Context context, Intent intent) {
        // Device admin enabled
        super.onEnabled(context, intent);
        Log.d(TAG, "Device Owner Enabled");
        Toast.makeText(context, "DemoAppDeviceAdminReceiver: Enable Device Admin", Toast.LENGTH_SHORT).show();
    }

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        // Return a message when a user tries to disable the device admin
        return "Disabling this device admin will remove important functionality.";
    }

    // Other overrides for admin events as required

    static ComponentName getComponentName(Context context){
        return new ComponentName(context.getApplicationContext(), DemoAppDeviceAdminReceiver.class);
    }


}

我的主要活动:-

package com.example.demo;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private int YOUR_REQUEST_CODE = 100;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ComponentName adminComponentName = new ComponentName(this, DemoAppDeviceAdminReceiver.class);

        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

            //TODO: To request Device Admin Activation
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, adminComponentName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Explanation of why your app      needs device admin access");
            //TODO: To start Activity that will prompt the user to grant device Admin privileges to the app
            startActivityForResult(intent, YOUR_REQUEST_CODE);

        //TODO: To check the app is device admin or not
        boolean isAdminActive = devicePolicyManager.isAdminActive(adminComponentName);

        if (isAdminActive) {
            // Your app is a device admin
            Toast.makeText(this, "Your app is a device admin", Toast.LENGTH_SHORT).show();

        } else {
            // Your app is not a device admin
            Toast.makeText(this, "Your app is not a device admin", Toast.LENGTH_SHORT).show();
        }

        //TODO: To check the app is device Owner or not
        if (devicePolicyManager.isDeviceOwnerApp("com.example.demo")) {
            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(adminComponentName);

    }

[enter image description here](https://i.stack.imgur.com/swnkZ.jpg)    //TODO: To handle the result of the device Admin Activation request
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == YOUR_REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                // Device admin was activated successfully
                Toast.makeText(this, "Device admin was activated successfully", Toast.LENGTH_SHORT).show();
            } else {
                // Device admin activation was canceled or failed
                Toast.makeText(this, "Device admin activation was canceled or failed", Toast.LENGTH_SHORT).show();

            }
        }
    }


}

我的清单文件:-

<?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.demo">


    <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"/>
    

<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/Theme.Demo"
        android:testOnly="false"
        >

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Declare the Device Admin Receiver -->
        <receiver
            android:name=".DemoAppDeviceAdminReceiver"
            android:label="@string/app_name"
            android:exported="true"
            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" />
        </receiver>

    </application>

</manifest>

device_admin_receive.xml:-

<?xml version="1.0" encoding="utf-8"?>
<device-admin>
    <uses-policies>
        <!-- Define device admin policies here -->
        <limit-password />
        <watch-login />
        <!-- Add other policies your app requires -->
        <reset-password />
        <force-lock />
        <wipe-data />
        <expire-password />
        <encrypted-storage />
        <disable-camera />
        <disable-keyguard-features />
    </uses-policies>
</device-admin>

我已经尝试过的:

使用 adb shell 命令在模拟器上安装应用程序 adb shell dpm set-device-owner com.example.demo/.DemoAppDeviceAdminReceiver

它成功地将应用程序设置为设备所有者。

使用上面的 adb 命令在真实设备上安装应用程序(恢复出厂设置并跳过登录页面后)。它成功地将应用程序设置为设备所有者。我认为这意味着问题出在二维码上。

我正在尝试将其安装在 Android 版本 13 的设备上。

现在,我的应用程序正在下载,但在安装时,它显示被 Play Protect 阻止,当我点击“仍然安装”时,它返回旧错误:无法设置设备 - 无法安装管理应用程序

android kotlin mdm device-admin device-owner
2个回答
0
投票

可能是您打开了“通过 USB 验证应用程序”。

这个“检查通过 ADB/ADT 安装的应用程序是否存在有害行为”,基本是将您的应用程序发送到 Google 进行审核,即使您自己从未将其提交给 Google。

可以在开发者系统设置中关闭此功能。


0
投票

我也有同样的问题。有可能你能帮我解决这个问题。我将不胜感激。

© www.soinside.com 2019 - 2024. All rights reserved.