Join us in person and online for Firebase Summit on October 18, 2022. Learn how Firebase can help you accelerate app development, release your app with confidence, and scale with ease. Register now

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. Open the Notifications composer and select New notification.

  4. Enter the message text.

  5. Select Send test message.

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

  7. Click Test

After you click 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: