Skip to content

Argument type of Context.RegisterReceiver() is different from native API #7503

Closed
@aqua-ix

Description

@aqua-ix

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

MonoAndroid 13.0, Xamarin.Android 13.1.0.1 , VS Mac 17.4

Description

I am currently updating the version of the target SDK for my Xamarin.Android project to version 33.

One of the new features of Android 13 is "Safer exporting of context-registered receivers".
https://developer.android.com/about/versions/13/features#runtime-receivers

To make my app compatible with this, I was going to change the RegisterReceiver call point as follows:

- Context.RegisterReceiver(receiver, filter);
+ Context.RegisterReceiver(receiver, filter, ReceiverFlags.Exported);

This implementation conforms to the specification of the following method: https://developer.android.com/reference/android/content/Context#registerReceiver(android.content.BroadcastReceiver,%20android.content.IntentFilter,%20java.lang.String,%20android.os.Handler)

However, the above code failed to compile.
After investigating the cause, I found that the third argument of MonoAndroid's RegisterReceiver() overload is not of type Int, but ActivityFlags. This differs from the native API specification.

Please let me know why this is happening and if MonoAndroid plans to fix it.

Steps to Reproduce

  1. Create new Xamarin.Android project that targeting MonoAndroid 13.0
  2. Call the following overloads of RegisterReceiver at any position:
    RegisterReceiver(BroadcastReceiver, IntentFilter, Int)

Did you find any workaround?

I have confirmed that ReceiverFlags can be used with ContextCompat API and will consider replacing it with ContextCompat in the near future if this issue is not resolved.
https://developer.android.com/reference/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions