55 lines
2.5 KiB
Java
55 lines
2.5 KiB
Java
package com.blackforestbytes.simplecloudnotifier;
|
|
|
|
import android.util.Log;
|
|
|
|
import com.google.firebase.messaging.FirebaseMessagingService;
|
|
import com.google.firebase.messaging.RemoteMessage;
|
|
|
|
public class FBMService extends FirebaseMessagingService
|
|
{
|
|
/**
|
|
* Called if InstanceID token is updated. This may occur if the security of
|
|
* the previous token had been compromised. Note that this is called when the InstanceID token
|
|
* is initially generated so this is where you would retrieve the token.
|
|
*/
|
|
@Override
|
|
public void onNewToken(String token)
|
|
{
|
|
Log.i("Firebase::NewToken", token);
|
|
}
|
|
|
|
@Override
|
|
public void onMessageReceived(RemoteMessage remoteMessage) {
|
|
// [START_EXCLUDE]
|
|
// There are two types of messages data messages and notification messages. Data messages are handled
|
|
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
|
|
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
|
|
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
|
|
// When the user taps on the notification they are returned to the app. Messages containing both notification
|
|
// and data payloads are treated as notification messages. The Firebase console always sends notification
|
|
// messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
|
|
// [END_EXCLUDE]
|
|
|
|
Log.i("FB::MessageReceived<0>", "");
|
|
|
|
|
|
// TODO(developer): Handle FCM messages here.
|
|
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
|
|
Log.i("FB::MessageReceived", "From: " + remoteMessage.getFrom());
|
|
|
|
// Check if message contains a data payload.
|
|
if (remoteMessage.getData().size() > 0) {
|
|
Log.i("FB::MessageReceived", "Payload: " + remoteMessage.getData());
|
|
}
|
|
|
|
// Check if message contains a notification payload.
|
|
if (remoteMessage.getNotification() != null) {
|
|
Log.i("FB::MessageReceived", "Notify_Title: " + remoteMessage.getNotification().getTitle());
|
|
Log.i("FB::MessageReceived", "Notify_Body: " + remoteMessage.getNotification().getBody());
|
|
}
|
|
|
|
// Also if you intend on generating your own notifications as a result of a received FCM
|
|
// message, here is where that should be initiated. See sendNotification method below.
|
|
}
|
|
}
|