Catch up on everything announced at Firebase Summit, and learn how Firebase can help you accelerate app development and run your app with confidence. Learn More

Send a test message to a backgrounded app

Stay organized with collections Save and categorize content based on your preferences.

To get started with FCM, build out the simplest use case: sending a test notification message from the Notifications composer to a development device when the app is in the background on the device. This page lists all the steps to achieve this, from setup to verification — it may cover steps you already completed if you have set up a Flutter app for FCM.

Install the FCM plugin

  1. Install and initialize the Firebase SDKs for Flutter if you haven't already done so.

  2. From the root of your Flutter project, run the following command to install the plugin:

    flutter pub add firebase_messaging
    
  3. Once complete, rebuild your Flutter application:

    flutter run
    

Access the registration token

To send a message to a specific device, you need to know that device's registration token. Because you'll need to enter the token in a field in the Notifications console to complete this tutorial, make sure to copy the token or securely store it after you retrieve it.

To retrieve the current registration token for an app instance, call getToken(). If notification permission has not been granted, this method will ask the user for notification permissions. Otherwise, it returns a token or rejects the future due to an error.

final fcmToken = await FirebaseMessaging.instance.getToken();

Send a test notification message

  1. Install and run the app on the target device. On Apple devices, you'll need to accept the request for permission to receive remote notifications.

  2. Make sure the app is in the background on the device.

  3. In the Firebase console, open the Messaging page.

  4. If this is your first message, select Create your first campaign.

    1. Select Firebase Notification messages and select Create.
  5. Otherwise, on the Campaigns tab, select New campaign and then Notifications.

  6. Enter the message text. All other fields are optional.

  7. Select Send test message from the right pane.

  8. In the field labeled Add an FCM registration token, enter the registration token you obtained in a previous section of this guide.

  9. Select Test.

After you select Test, the targeted client device (with the app in the background) should receive the notification.

For insight into message delivery to your app, see the FCM reporting dashboard, which records the number of messages sent and opened on Apple and Android devices, along with data for "impressions" (notifications seen by users) for Android apps.

Next steps

Send messages to foregrounded apps

Once you have successfully sent notification messages while your app is in the background, see Receive Messages in a Flutter App to get started sending to foregrounded apps.

Go beyond notification messages

To add other, more advanced behavior to your app, you'll need a server implementation.

Then, in your app client: