我正在Xamarin.Android中运行一个ENEPRESE应用,仅在满足特定条件时才应将其禁用为设备管理员
我的代码示例如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.App.Admin;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace MyApp
{
[BroadcastReceiver(Permission = "android.permission.BIND_DEVICE_ADMIN")]
[MetaData("android.app.device_admin", Resource = "@xml/device_admin")]
[IntentFilter(new[] { "android.app.action.DEVICE_ADMIN_ENABLED", Intent.ActionMain }, Priority = (int)IntentFilterPriority.HighPriority)]
public class DeviceAdmin : DeviceAdminReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if (intent.ToString().Contains("DEVICE_ADMIN_DISABLE"))
{
if (certain condition==true)
{
//Cancel the Intent or Broadcast to disable Deviceadmin
}
else
{
//Device Admin is Disabled successfully
}
base.OnReceive(context, intent);
}