设备管理列表不显示我的应用程序

a0x5cqrl  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(250)

我想在android 10中访问我的工厂mac地址,根据android的文档,我应该为我的应用程序启用管理权限。我已经按照文档一步一步地做了。我在清单中设置了我的admin receiver,并声明了一个扩展adminreceiver的customadminreceiver:

public class CustomAdminReceiver extends DeviceAdminReceiver {

void showToast(Context context, String msg) {
    String status = context.getString(R.string.admin_receiver_status, msg);
    Toast.makeText(context, status, Toast.LENGTH_SHORT).show();
}

@Override
public void onEnabled(Context context, Intent intent) {
    showToast(context, context.getString(R.string.admin_receiver_status_enabled));
}

@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
    return context.getString(R.string.admin_receiver_status_disable_warning);
}

@Override
public void onDisabled(Context context, Intent intent) {
    showToast(context, context.getString(R.string.admin_receiver_status_disabled));
}

@Override
public void onPasswordChanged(Context context, Intent intent, UserHandle userHandle) {
    showToast(context, context.getString(R.string.admin_receiver_status_pw_changed));
}

}
以及舱单:

<receiver android:name=".Receiver.CustomAdminReceiver"
        android:label="@string/sap_device_admin"
        android:description="@string/sap_device_admin_description"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data android:name="android.app.deviceAdmin"
            android:resource="@xml/device_admin" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>

我还启动了一个自定义对话框来显示管理设置页,并在onactivityresults中显示结果:

customAlertDialog.showLogMessageAlert(SplashActivity.this, false, "", getResources().getString(R.string.macRandomization), Constants.INFO_MESSAGE(), getResources().getString(R.string.cancel), getResources().getString(R.string.apply), new CustomAlertDialogResponse() {
        @Override
        public void setOnCancelClick() {
            finish();
        }

        @Override
        public void setOnApplyClick() {

            componentName=new  ComponentName("com.android.settings", "com.android.settings.DeviceAdminSettings");

            startActivityForResult(new Intent().setComponent(componentName),REQUEST_CODE_ENABLE_ADMIN);

        }

活动结果:

if (requestCode == REQUEST_CODE_ENABLE_ADMIN) {
        switch (resultCode) {
            // End user cancels the request
            case Activity.RESULT_CANCELED:

                Log.d("kfopejkf", "onActivityResult: " + getResources().getString(R.string.encryption_status_inactive));
                break;
            // End user accepts the request
            case Activity.RESULT_OK:
                if (mDPM.isDeviceOwnerApp(getPackageName())) {
                    mDPM.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
                } else {
                    Toast.makeText(this, "This app is not the device owner", Toast.LENGTH_SHORT).show();
                }
                if (mDPM.isDeviceOwnerApp(getPackageName())) {
                    mDPM.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
                } else {
                    Toast.makeText(this, "This app is not the device owner", Toast.LENGTH_SHORT).show();
                }
                Log.d("feinfp", "onActivityResult: " + getResources().getString(R.string.encryption_status_inactive));
                break;
        }

当我从我的应用程序中获取管理应用程序列表时,我可以看到我的应用程序以及其他一些应用程序,但它没有显示在管理设置列表中。我还检查了我的应用程序是否安装在内部存储上:

android:installLocation="internalOnly"

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题