Google is committed to advancing racial equity for Black communities. See how.

CloudMessagingReceiver

public abstract class CloudMessagingReceiver extends BroadcastReceiver

BroadcastReceiver that receives Cloud Messaging events as broadcasts and delivers them to callback methods in the application-specific subclass declared in the manifest:

 <receiver
     android:name="com.example.YourCloudMessagingReceiver"
     android:exported="true"
     android:permission="com.google.android.c2dm.permission.SEND" >
     <intent-filter>
         <action android:name="com.google.android.c2dm.intent.RECEIVE" />
         <category android:name="YOUR_PACKAGE_NAME" />
     </intent-filter>
 </receiver>

The com.google.android.c2dm.permission.SEND permission is held by Google Play services. This prevents other apps from invoking the broadcast receiver.

Nested Class Summary

class CloudMessagingReceiver.IntentActionKeys Actions for the wrapped Intent of notification action broadcasts to indicate the notification action type. 
class CloudMessagingReceiver.IntentKeys Keys used to pass data within the broadcast Intent's extras. 

Public Constructor Summary

Public Method Summary

final void
onReceive(Context context, Intent intent)
This method is called when the BroadcastReceiver is receiving an Intent broadcast.

Protected Method Summary

Executor
getBroadcastExecutor()
Returns the Executor to use to handle broadcasts on.
abstract int
onMessageReceive(Context context, CloudMessage message)
Called when a message is received.
void
onNotificationDismissed(Context context, Bundle data)
Called when a notification created from a cloud message has been dismissed.
void
onNotificationOpen(Context context, Bundle data)
Called when a notification created from a cloud message has been opened.

Inherited Method Summary

Public Constructors

public CloudMessagingReceiver ()

Public Methods

public final void onReceive (Context context, Intent intent)

This method is called when the BroadcastReceiver is receiving an Intent broadcast. Subclasses should instead override the callback onMessageReceive(Context, CloudMessage) (and optionally onNotificationOpen(Context, Bundle) and onNotificationDismissed(Context, Bundle)) to handle events received by this.

Protected Methods

protected Executor getBroadcastExecutor ()

Returns the Executor to use to handle broadcasts on. Defaults to a single threaded Executor.

protected abstract int onMessageReceive (Context context, CloudMessage message)

Called when a message is received. Runs on the Executor returned by getBroadcastExecutor().

Parameters
context The Context in which the receiver is running.
message The message that is being received.
Returns
  • Activity.RESULT_OK if the message was received correctly or an error code if it was not.

protected void onNotificationDismissed (Context context, Bundle data)

Called when a notification created from a cloud message has been dismissed. Runs on the Executor returned by getBroadcastExecutor(). Defaults to do nothing.

Parameters
context The Context in which the receiver is running.
data Data related to the notification that was dismissed.

protected void onNotificationOpen (Context context, Bundle data)

Called when a notification created from a cloud message has been opened. Runs on the Executor returned by getBroadcastExecutor(). Defaults to do nothing.

Parameters
context The Context in which the receiver is running.
data Data related to the notification that was opened.