Top level Firebase Cloud Messaging singleton that provides methods for subscribing to topics and sending upstream messages.
In order to receive Firebase messages, declare an implementation of FirebaseMessagingService
in the app manifest. To process messages, override base class methods to handle any events
required by the application.
Client apps can send upstream messages back to the app server using the XMPP-based Cloud Connection Server. For example:
FirebaseMessaging.getInstance().send(
new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com")
.setMessageId(id)
.addData("key", "value")
.build());
| String | INSTANCE_ID_SCOPE | Specifies scope used in obtaining a registration
token when calling getToken() |
| Task<Void> |
deleteToken()
Deletes the FCM registration token for this Firebase project.
|
| boolean |
deliveryMetricsExportToBigQueryEnabled()
Determines whether Firebase Cloud Messaging exports message delivery metrics to
BigQuery.
|
| synchronized static FirebaseMessaging | |
| Task<String> |
getToken()
Returns the FCM registration token for this Firebase project.
|
| boolean |
isAutoInitEnabled()
Determines whether FCM auto-initialization is enabled or disabled.
|
| void | |
| void |
setAutoInitEnabled(boolean enable)
Enables or disables auto-initialization of Firebase Cloud Messaging.
|
| void |
setDeliveryMetricsExportToBigQuery(boolean enable)
Enables or disables Firebase Cloud Messaging message delivery metrics export to
BigQuery.
|
| Task<Void> | |
| Task<Void> |
Specifies scope used in obtaining a registration token when calling getToken()
Deletes the FCM registration token for this Firebase project.
Note that if auto-init is enabled, a new token will be generated the next time the
app is started. Disable auto-init (setAutoInitEnabled(boolean))
to avoid this.
Note that this does not delete the Firebase Installations ID that may have been
created when generating the token. See FirebaseInstallations.delete() for
deleting that.
Determines whether Firebase Cloud Messaging exports message delivery metrics to BigQuery.
Returns the FCM registration token for this Firebase project.
This creates a Firebase Installations ID, if one does not exist, and sends
information about the application and the device where it's running to the Firebase
backend. See
deleteToken() for information on deleting the token and the Firebase
Installations ID.
Task with
the token.Determines whether FCM auto-initialization is enabled or disabled.
Sends message upstream to your app server.
When there is an active connection the message will be sent immediately, otherwise the message will be queued up to the time to live (TTL) set in the message.
Enables or disables auto-initialization of Firebase Cloud Messaging.
When enabled, Firebase Cloud Messaging generates a registration token on app startup
if there is no valid one (see
getToken()) and periodically sends data to the Firebase backend to validate
the token. This setting is persisted across app restarts and overrides the setting
specified in your manifest.
By default, Firebase Cloud Messaging auto-initialization is enabled. If you need to change the default, (for example, because you want to prompt the user before Firebase Cloud Messaging generates/refreshes a registration token on app startup), add to your application’s manifest:
<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
| enable | Whether Firebase Cloud Messaging should auto-initialize. |
|---|
Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery.
By default, message delivery metrics are not exported to BigQuery. Use this method to enable or disable the export at runtime. In addition, you can enable the export by adding to your manifest. Note that the run-time method call will override the manifest value.
<meta-data android:name= "delivery_metrics_exported_to_big_query_enabled"
android:value="true"/>
| enable | Whether Firebase Cloud Messaging should export message delivery metrics to BigQuery. |
|---|
Subscribes to topic in the background.
The subscribe operation is persisted and will be retried until successful.
This uses an FCM registration token to identify the app instance, generating one if
it does not exist (see
getToken()), which perodically sends data to the Firebase backend when
auto-init is enabled. To delete the data, delete the token (deleteToken())
and the Firebase Installations ID (FirebaseInstallations.delete()). To
stop the periodic sending of data, disable auto-init (setAutoInitEnabled(boolean)).
| topic | The name of the topic to subscribe. Must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}". |
|---|
Unsubscribes from topic in the background.
The unsubscribe operation is persisted and will be retried until successful.
| topic | The name of the topic to unsubscribe from. Must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}". |
|---|