Bug 14875 - Missing intent and value from BroadcastReceiver
Summary: Missing intent and value from BroadcastReceiver
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.8.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2013-09-20 05:26 UTC by Paul Johnson
Modified: 2013-09-24 13:03 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Paul Johnson 2013-09-20 05:26:13 UTC
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;

Intent.ActionBindDeviceAdmin (presumably) is missing and the Description parameter in the BroadcastReceiver metadata is missing.

If I use the name parameter for the app name, I get a duplicate name error in the Java created code.

Without the Description being there, the BroadcastReceiver will not fire
Comment 1 Atsushi Eno 2013-09-24 07:31:16 UTC
Note that those attributes are based only on XML attributes. So if there is no corresponding attribute, we won't add anything because that doesn't make sense. That's why there is no such members you expect in our attribute classes.

Also there is no such a field BIND_DEVICE_ADIM in Java android.content.Intent either, so you won't see corresponding member in Xamarin either (neither now nor future). You should be able to directly specify the string value "android.app.action.DEVICE_ADMIN_ENABLED".
Comment 2 Paul Johnson 2013-09-24 08:16:01 UTC
While the attributes are based on XML attributes, without the ability to add them to the manifest correctly, the setting of the device admin can't be done. Any suggestions on how to achieve the addition to the manifest?
Comment 3 Atsushi Eno 2013-09-24 09:10:08 UTC
>without the ability to add them to the manifest correctly, the setting of the device admin can't be done.

No, you can always create AndroidManifest.xml and write whatever you need there. Then your attribute-based manifest elements will be merged into the intermediate AndroidManifest.xml and then packaged it into the final apk.
Comment 4 Paul Johnson 2013-09-24 09:23:21 UTC
I thought when the code was built, the code generator created the manifest used by the java build, so anything that had to be in the java manifest had to be generated in code rather than being copied from the monodroid manifest
Comment 5 Jonathan Pryor 2013-09-24 11:29:07 UTC
@Paul: Please see: http://docs.xamarin.com/guides/android/advanced_topics/working_with_androidmanifest.xml

> AndroidManifest.xml is generated as part of the build process, and the XML found within
> Properties\AndroidManifest.xml is merged with XML generated based on custom attributes.

This is in fact how permissions are handled: the IDE just adds/removes the appropriate XML fragments from Properties\AndroidManifest.xml, and Properties\AndroidManifest.xml is "merged" with the generated XML to create the "final" e.g. obj\Debug\android\AndroidManifest.xml.
Comment 6 Paul Johnson 2013-09-24 13:03:13 UTC
That's cleared that up - thanks :)