Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

G.3 First Message

Hadi Tavakoli edited this page Jun 16, 2019 · 3 revisions

Send a notification message

After initializing the FCM and retriving the token, follow the steps below to send your first notification message:

  1. Install and run the app on the target device.
  2. Make sure the app is in background mode or killed.
  3. Open the Notifications tab of the Firebase console and select New Message.
  4. Enter the message text.
  5. Select Single Device for the message target.
  6. In the field labeled FCM Registration Token, enter the registration token you obtained in a previous section of this guide.

After you click Send Message, targeted client devices will receive the notification in the system notifications tray.

NOTICE: There are generally two types of messages, data messages and notification messages. Please read the information on this page carefully to understand the difference between these FCM messages. These information has been customized for AIR developers. However if you wish to read the original documentation about the concept of FCM messages, check here: https://firebase.google.com/docs/cloud-messaging/concept-options

Send messages to foregrounded apps

When your app is in foreground, you can listen to FcmEvents.MESSAGE to know when a notification is received. If you are sending a notification message from your Firebase console, you still can set key/value pairs of custom payload data.

FCM.listener.addEventListener(FcmEvents.MESSAGE, onMessage);

function onMessage(e:FcmEvents):void
{
	trace(e.msg)
	var payload:Object = FCM.parsePayloadFromString(e.msg);
	
	if (payload)
	{
		for (var name:String in payload)
		{
			trace(name + " = " + payload[name]);
		}
	}
}

NOTICE: Firebase console (currently) sends notification messages only. If you wish to send data messages, you need to perform a POST to the following URL https://fcm.googleapis.com/fcm/send including the below headers:

Key: Content-Type, Value: application/json
Key: Authorization, Value: key=<your-server-key>

{
	"data": 
	{
		"key": "value"
	},
	"priority": "high",
	"registration_ids": 
	[
		"your-device-token",
		"your-device2-token",
		"your-device3-token",
		".........."
	]
}

HINT: You can find your server key in the firebase console: Your project, settings, Project settings, Cloud messaging, Server Key.

To learn more about how you should send notifications using your own server, you need to refer to Firebase original FCM documents. You may also find the information on this issue helpful.

Moreover, we have written a very helpful post about how you can build your own FCM console for sending out FCM messages. You can find the article here.

Receive payload data when opening the app from notification

When your app is closed/in background, an FCM message will result in creating a notification. When you click on the notification, your app opens and you can listen to InvokeEvent.INVOKE event to read the payload data that your message may include.

NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);

function onInvoke(e:InvokeEvent):void
{
	var payload:Object = FCM.parsePayloadFromArguments(e.arguments);
	
	if (payload) // If available, it means that the Invoke listener contains FCM data
	{
		for (var name:String in payload)
		{
			trace(name + " = " + payload[name]);
		}
	}
}

Introduction to Firebase ANEs collection for Adobe Air apps


Get Started with Firebase Core in AIR

  1. Prerequisites
  2. Add Firebase to your app
  3. Add the Firebase SDK
  4. Init Firebase Core
  5. Available ANEs
  6. Managing Firebase iid

Get Started with Analytics

  1. Add Analytics ANE
  2. Init Analytics ANE
  3. Log Events
  4. Set User Properties

Get Started with Crashlytics

  1. Add Crashlytics ANE
  2. Test Your Implementation
  3. Customize Crash Reports
  4. Upload .dSYM for iOS apps

Get Started with DynamicLinks

  1. Add DynamicLinks ANE
  2. Init DynamicLinks ANE
  3. Create DynamicLinks
  4. Receive DynamicLinks
  5. View Analytics

Get Started with Authentication

  1. Add Authentication
  2. Init Authentication
  3. Manage Users
  4. Phone Number
  5. Custom Auth
  6. Anonymous Auth
  7. State in Email Actions
  8. Email Link Authentication

Get Started with FCM + OneSignal

  1. Add FCM ANE
  2. Init FCM ANE
  3. Send Your 1st Message
  4. Send Msg to Topics
  5. Understanding FCM Messages
  6. init OneSignal

Get Started with Firestore

  1. Add Firestore
  2. Init Firestore
  3. Add Data
  4. Transactions & Batches
  5. Delete Data
  6. Manage the Console
  7. Get Data
  8. Get Realtime Updates
  9. Simple and Compound
  10. Order and Limit Data
  11. Paginate Data
  12. Manage Indexes
  13. Secure Data
  14. Offline Data
  15. Where to Go From Here

Get Started with Realtime Database

  1. Add Realtime Database
  2. Init Realtime Database
  3. Structure Your Database
  4. Save Data
  5. Retrieve Data
  6. Enable Offline Capabilities

Get Started with Remote Config

  1. Parameters and Conditions
  2. Add Remote Config
  3. Init Remote Config

Get Started with Performance

  1. Add Performance ANE
  2. Init & Start Monitoring

Get Started with Storage

  1. Add Storage ANE
  2. Init Storage ANE
  3. Upload Files to Storage
  4. Download Files to Air
  5. Use File Metadata
  6. Delete Files

Get Started with Functions

  1. Write & Deploy Functions
  2. Add Functions ANE
  3. Init Functions
Clone this wiki locally