top of page

[Flutter/dart] Send a test message of Firebase Messaging


Overview

When you use Firebase Messaging, you'll want to send a test to your device.

It took a little time, so I will summarize how to do it.


Method

How to send a test message


Test messages are created in Cloud Messaging> Create Notifications in the Firebase console. Enter the "Notification Title" and "Notification Text" appropriately, and click "Send Test Message" on the right side. This will bring up a screen where you can enter your FCM token. If you enter the token of your device here, you can send a message only to that device.





get token


Here's how to get a token with dart. This process is executed when the app is launched to get the token of the device.


import 'package:firebase_messaging/firebase_messaging.dart';

final messaging=FirebaseMessaging.instance;
String _token=await messaging.getToken();

Enter this value in the previous console and send the message.



Caution


By default, you will not be notified when the app is running in the foreground.

Put the app in the background for confirmation.

(I didn't notice this and spent a lot of wasted time.)



Lastly

In the case where you send a message only to specific users who meet certain conditions, it is necessary to obtain the token once using the above method as well.

Recent Posts

See All

Comments


category

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page