晚上好,
我试图在我的deviceadmin应用程序上启动startlocktask。
但是当我启动命令devicePolicyManager.SetLockTaskPackages(packageName) my app crash.
时
我试图发射
devicePolicyManager.IsDeviceOwnerApp(PackageName)
但结果是每次都是假的。
我可以在配置设备管理员下看到我的应用程序。但我无法启动命令setstatusbar或startlocktask,因为该应用程序似乎没有管理员权限
我的代码是:
protected override void OnCreate(Bundle bundle)
{ DevicePolicyManager devicePolicyManager = (DevicePolicyManager)GetSystemService(Context.DevicePolicyService);
ComponentName demoDeviceAdmin = new ComponentName(this, Java.Lang.Class.FromType(typeof(DeviceAdmin)));
Intent intent = new Intent(DevicePolicyManager.ActionAddDeviceAdmin);
intent.PutExtra(DevicePolicyManager.ExtraDeviceAdmin, demoDeviceAdmin);
intent.PutExtra(DevicePolicyManager.ExtraAddExplanation, "Device administrator");
StartActivity(intent);
string x2 = demoDeviceAdmin.ClassName;
string x3 = demoDeviceAdmin.ShortClassName;
// devicePolicyManager.SetStatusBarDisabled(demoDeviceAdmin, true);
Toast.MakeText(this, devicePolicyManager.IsDeviceOwnerApp(PackageName).ToString(), ToastLength.Long).Show();
}
我的活动是:
public class MainActivity : Activity
{
[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 })]
public class DeviceAdmin : DeviceAdminReceiver
{
public override void OnEnabled(Context context, Intent intent)
{
base.OnEnabled(context, intent);
Toast.MakeText(context, "DeviceAdmin", ToastLength.Short).Show();
}
public override void OnDisabled(Context context, Intent intent)
{
base.OnDisabled(context, intent);
}
public override void OnPasswordChanged(Context context, Intent intent)
{
base.OnPasswordChanged(context, intent);
}
public override void OnPasswordFailed(Context context, Intent intent)
{
base.OnPasswordFailed(context, intent);
}
public override void OnPasswordSucceeded(Context context, Intent intent)
{
base.OnPasswordSucceeded(context, intent);
}
}
我的device_admin
<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>
我的清单是:
<receiver android:permission="android.permission.BIND_DEVICE_ADMIN" android:name="md51e9ac75480e1224184ffdf189ecfeb54.MainActivity_DeviceAdmin">
<meta-data android:name="android.app.device_admin" android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</receiver>
但没办法..这不起作用。 怎么了? 有谁可以帮助我吗? 谢谢 问候 安德烈