微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决设备管理列表未显示我的应用程序

我想在 android 10 中访问我的工厂 mac 地址,根据 android 的文档,我应该为我的应用程序启用管理员权限。我已经按照文档一步一步地完成了。我设置了我的管理员接收器清单并声明一个扩展 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,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);

        }

onActivityResults:

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,Toast.LENGTH_SHORT).show();
                }
                Log.d("feinfp","onActivityResult: " + getResources().getString(R.string.encryption_status_inactive));
                break;
        }

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

        android:installLocation="internalOnly"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。