Forum Xamarin.Android

Implementing DeviceAdmin in code problem

nodoidnodoid GBMember, Beta ✭✭✭

Hi,

I'm not sure if this is right, but I think I've unearthed a missing Action and missing BroadcastReceiver parameter as well as bug on top!

I'm trying to implement a DeviceAdminReceiver following the code on the Android developer website (http://developer.android.com/guide/topics/admin/device-admin.html) and stack overflow (http://stackoverflow.com/questions/7716797/monodroid-how-to-create-receiver-meta-data-clause-in-manisfest-xml)

I have this so far

    [BroadcastReceiver (Label = "@string/uninstall",
                        Permission = "android.permission.BIND_DEVICE_ADMIN")]
    [MetaData ("name", Value = "device_admin")]
    [IntentFilter (new []{"android.app.action.DEVICE_ADMIN_ENABLED", Intent.ActionMain})]
    public class DeviceAdminBroadcastReceiver : Android.App.Admin.DeviceAdminReceiver
    {
        public override void OnEnabled(Context context, Intent intent)
        {
            Toast.MakeText(context, Resource.String.lockenabled, ToastLength.Long).Show();   
        }

        public override Java.Lang.ICharSequence OnDisableRequestedFormatted(Context context, Intent intent)
        {
            Toast.MakeText(context, Resource.String.lockrequestno, ToastLength.Long).Show();
            return null;
        }
    }

The intent filter is missing, the Description parameter in the BroadcastReceiver is missing (not implemented) and if I use the name parameter for the app name, I get a duplicate name error in the Java created code (bug?). The metadata should read "Resource", but that too is not implemented from what I can see (there is a Resource (string get;set;) but that gives an error when used [string not allowed])

As far as the code goes, it doesn't get called. I'm not sure if there should be an activity associated with this or if it's just the bits missing from the receiver that is at fault. The Value in the metadata is just an xml file copied from the Android dev site and put into the Values directory.

Any help or advice on this would be appreciated - I can't find any sort of demo apps showing how this is done.

Paul

Posts

Sign In or Register to comment.