ContextWrapper.RegisterReceiver Method

Definition

Overloads

Name Description
RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler, ActivityFlags)
Obsolete.

Register to receive intent broadcasts, to run in the context of scheduler . See registerReceiver(BroadcastReceiver,IntentFilter,int) and registerReceiver(BroadcastReceiver,IntentFilter,String,Handler) for more information. See BroadcastReceiver for more information on Intent broadcasts. As of Build.VERSION_CODES.UPSIDE_DOWN_CAKE , the system can place context-registered broadcasts in a queue while the app is in the cached state . When the app leaves the cached state, such as returning to the foreground, the system delivers any queued broadcasts. Multiple instances of certain broadcasts might be merged into one broadcast. As of Build.VERSION_CODES.ICE_CREAM_SANDWICH , receivers registered with this method will correctly respect the Intent.setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security. Parameters receiver BroadcastReceiver : This value may be null .

RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler)

Register to receive intent broadcasts, to run in the context of <var>scheduler</var>.

RegisterReceiver(BroadcastReceiver, IntentFilter)

Register a BroadcastReceiver to be run in the main activity thread.

RegisterReceiver(BroadcastReceiver, IntentFilter, ActivityFlags)
Obsolete.

Register to receive intent broadcasts, with the receiver optionally being exposed to Instant Apps. See registerReceiver(BroadcastReceiver,IntentFilter) for more information. By default Instant Apps cannot interact with receivers in other applications, this allows you to expose a receiver that Instant Apps can interact with. See BroadcastReceiver for more information on Intent broadcasts. As of Build.VERSION_CODES.UPSIDE_DOWN_CAKE , the system can place context-registered broadcasts in a queue while the app is in the cached state . When the app leaves the cached state, such as returning to the foreground, the system delivers any queued broadcasts. Multiple instances of certain broadcasts might be merged into one broadcast. As of Build.VERSION_CODES.ICE_CREAM_SANDWICH , receivers registered with this method will correctly respect the Intent.setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security. Parameters receiver BroadcastReceiver : This value may be null .

RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler, ActivityFlags)

Caution

This method has an incorrect enumeration type. Use the overload that takes ReceiverFlags instead.

Register to receive intent broadcasts, to run in the context of scheduler . See registerReceiver(BroadcastReceiver,IntentFilter,int) and registerReceiver(BroadcastReceiver,IntentFilter,String,Handler) for more information. See BroadcastReceiver for more information on Intent broadcasts. As of Build.VERSION_CODES.UPSIDE_DOWN_CAKE , the system can place context-registered broadcasts in a queue while the app is in the cached state . When the app leaves the cached state, such as returning to the foreground, the system delivers any queued broadcasts. Multiple instances of certain broadcasts might be merged into one broadcast. As of Build.VERSION_CODES.ICE_CREAM_SANDWICH , receivers registered with this method will correctly respect the Intent.setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security. Parameters receiver BroadcastReceiver : This value may be null .

[Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;Ljava/lang/String;Landroid/os/Handler;I)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_Ljava_lang_String_Landroid_os_Handler_IHandler", ApiSince=26)]
[System.Obsolete("This method has an incorrect enumeration type. Use the overload that takes ReceiverFlags instead.")]
public override Android.Content.Intent? RegisterReceiver(Android.Content.BroadcastReceiver? receiver, Android.Content.IntentFilter? filter, string? broadcastPermission, Android.OS.Handler? scheduler, Android.Content.ActivityFlags flags);
[<Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;Ljava/lang/String;Landroid/os/Handler;I)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_Ljava_lang_String_Landroid_os_Handler_IHandler", ApiSince=26)>]
[<System.Obsolete("This method has an incorrect enumeration type. Use the overload that takes ReceiverFlags instead.")>]
override this.RegisterReceiver : Android.Content.BroadcastReceiver * Android.Content.IntentFilter * string * Android.OS.Handler * Android.Content.ActivityFlags -> Android.Content.Intent

Parameters

receiver
BroadcastReceiver

The broadcast receiver to register.

filter
IntentFilter

The intent filter that selects broadcasts to receive.

broadcastPermission
String

Name of a permission that a broadcaster must hold to send an Intent to this receiver. If null, no permission is required.

scheduler
Handler

The handler on which receiver callbacks run.

flags
ActivityFlags

The flags that control this operation.

Returns

The first sticky intent found that matches filter , or null if there are none.

Attributes

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Java documentation for android.content.ContextWrapper.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter, java.lang.String, android.os.Handler, int).

Applies to

RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler)

Register to receive intent broadcasts, to run in the context of <var>scheduler</var>.

[Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;Ljava/lang/String;Landroid/os/Handler;)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_Ljava_lang_String_Landroid_os_Handler_Handler")]
public override Android.Content.Intent? RegisterReceiver(Android.Content.BroadcastReceiver? receiver, Android.Content.IntentFilter? filter, string? broadcastPermission, Android.OS.Handler? scheduler);
[<Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;Ljava/lang/String;Landroid/os/Handler;)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_Ljava_lang_String_Landroid_os_Handler_Handler")>]
override this.RegisterReceiver : Android.Content.BroadcastReceiver * Android.Content.IntentFilter * string * Android.OS.Handler -> Android.Content.Intent

Parameters

receiver
BroadcastReceiver

The BroadcastReceiver to handle the broadcast.

filter
IntentFilter

Selects the Intent broadcasts to be received.

broadcastPermission
String

Name of a permission that a broadcaster must hold to send an Intent to this receiver. If null, no permission is required.

scheduler
Handler

Handler identifying the thread that will receive the Intent. If null, the main thread of the process will be used.

Returns

The first sticky intent found that matches filter , or null if there are none.

Attributes

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Java documentation for android.content.ContextWrapper.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter, java.lang.String, android.os.Handler).

Applies to

RegisterReceiver(BroadcastReceiver, IntentFilter)

Register a BroadcastReceiver to be run in the main activity thread.

[Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_Handler")]
public override Android.Content.Intent? RegisterReceiver(Android.Content.BroadcastReceiver? receiver, Android.Content.IntentFilter? filter);
[<Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_Handler")>]
override this.RegisterReceiver : Android.Content.BroadcastReceiver * Android.Content.IntentFilter -> Android.Content.Intent

Parameters

receiver
BroadcastReceiver

The BroadcastReceiver to handle the broadcast.

filter
IntentFilter

Selects the Intent broadcasts to be received.

Returns

Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter , in the main application thread. The system may broadcast Intents that are "sticky" -- these stay around after the broadcast has finished, to be sent to any later registrations. If your IntentFilter matches one of these sticky Intents, that Intent will be returned by this function and sent to your receiver as if it had just been broadcast. There may be multiple sticky Intents that match filter , in which case each of these will be sent to receiver . In this case, only one of these can be returned directly by the function; which of these that is returned is arbitrarily decided by the system. If you know the Intent you are registering for is sticky, you can supply null for your receiver . In this case, no receiver is registered -- the function simply returns the sticky Intent that matches filter . In the case of multiple matches, the same rules as described above apply. See BroadcastReceiver for more information on Intent broadcasts. As of Build.VERSION_CODES.UPSIDE_DOWN_CAKE , the system can place context-registered broadcasts in a queue while the app is in the cached state . When the app leaves the cached state, such as returning to the foreground, the system delivers any queued broadcasts. Multiple instances of certain broadcasts might be merged into one broadcast. As of Build.VERSION_CODES.ICE_CREAM_SANDWICH , receivers registered with this method will correctly respect the Intent.setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security. For apps targeting Build.VERSION_CODES.UPSIDE_DOWN_CAKE , either RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED must be specified if the receiver is not being registered for system broadcasts or a SecurityException will be thrown. See registerReceiver(BroadcastReceiver,IntentFilter,int) to register a receiver with flags. Note: this method cannot be called from a BroadcastReceiver component; that is, from a BroadcastReceiver that is declared in an application's manifest. It is okay, however, to call this method from another BroadcastReceiver that has itself been registered at run time with registerReceiver(BroadcastReceiver, IntentFilter) , since the lifetime of such a registered BroadcastReceiver is tied to the object that registered it. Parameters receiver BroadcastReceiver : This value may be null . filter IntentFilter : Selects the Intent broadcasts to be received. Returns Intent The first sticky intent found that matches filter , or null if there are none.

Attributes

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Java documentation for android.content.ContextWrapper.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter).

Applies to

RegisterReceiver(BroadcastReceiver, IntentFilter, ActivityFlags)

Caution

This method has an incorrect enumeration type. Use the overload that takes ReceiverFlags instead.

Register to receive intent broadcasts, with the receiver optionally being exposed to Instant Apps. See registerReceiver(BroadcastReceiver,IntentFilter) for more information. By default Instant Apps cannot interact with receivers in other applications, this allows you to expose a receiver that Instant Apps can interact with. See BroadcastReceiver for more information on Intent broadcasts. As of Build.VERSION_CODES.UPSIDE_DOWN_CAKE , the system can place context-registered broadcasts in a queue while the app is in the cached state . When the app leaves the cached state, such as returning to the foreground, the system delivers any queued broadcasts. Multiple instances of certain broadcasts might be merged into one broadcast. As of Build.VERSION_CODES.ICE_CREAM_SANDWICH , receivers registered with this method will correctly respect the Intent.setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security. Parameters receiver BroadcastReceiver : This value may be null .

[Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;I)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_IHandler", ApiSince=26)]
[System.Obsolete("This method has an incorrect enumeration type. Use the overload that takes ReceiverFlags instead.")]
public override Android.Content.Intent? RegisterReceiver(Android.Content.BroadcastReceiver? receiver, Android.Content.IntentFilter? filter, Android.Content.ActivityFlags flags);
[<Android.Runtime.Register("registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;I)Landroid/content/Intent;", "GetRegisterReceiver_Landroid_content_BroadcastReceiver_Landroid_content_IntentFilter_IHandler", ApiSince=26)>]
[<System.Obsolete("This method has an incorrect enumeration type. Use the overload that takes ReceiverFlags instead.")>]
override this.RegisterReceiver : Android.Content.BroadcastReceiver * Android.Content.IntentFilter * Android.Content.ActivityFlags -> Android.Content.Intent

Parameters

receiver
BroadcastReceiver

The broadcast receiver to register.

filter
IntentFilter

The intent filter that selects broadcasts to receive.

flags
ActivityFlags

The flags that control this operation.

Returns

The first sticky intent found that matches filter , or null if there are none.

Attributes

Remarks

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Java documentation for android.content.ContextWrapper.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter, int).

Applies to