本文整理匯總了Java中com.google.firebase.messaging.RemoteMessage.getNotification方法的典型用法代碼示例。如果您正苦於以下問題:Java RemoteMessage.getNotification方法的具體用法?Java RemoteMessage.getNotification怎麽用?Java RemoteMessage.getNotification使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.firebase.messaging.RemoteMessage
的用法示例。
在下文中一共展示了RemoteMessage.getNotification方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Utils.d("Message From: " + remoteMessage.getFrom());
Utils.d("Message From: " + remoteMessage.toString());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();
Utils.d("Message data payload: " + data.toString());
KeyValueStorage.set_context(this);
handleData(data);
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Utils.d(
"Notification Body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody(), this);
}
}
示例2: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String notificationTitle = null, notificationBody = null;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
notificationTitle = remoteMessage.getNotification().getTitle();
notificationBody = 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.
sendNotification(notificationTitle, notificationBody);
}
示例3: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification 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.
}
示例4: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0) {
// procesa los datos extra de la notificación
}
if (remoteMessage.getNotification() != null) {
String title = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();
String clickAction = remoteMessage.getNotification().getClickAction();
Log.d(TAG, "Title: " + title);
Log.d(TAG, "Message: " + message);
Log.d(TAG, "clickAction: " + clickAction);
sendNotification(title, message, clickAction);
}
}
示例5: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Map<String, String> data = remoteMessage.getData();
sendNotification(data.get("message"),data.get("title"));
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification 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.
}
示例6: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Log.e(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage == null)
return;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
//Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
handleNotification(remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
//Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
} catch (Exception e) {
//Log.e(TAG, "Exception: " + e.getMessage());
}
}
}
示例7: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
}
示例8: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (!GameDatabase.getInstance().credentialsStored(this)) {
//We are not logged in, do nothing.
return;
}
String json = remoteMessage.getData().get("announcement");
if (json != null) {
Announcement ann = JsonUtils.jsonToObject(json, Announcement.class);
if (ann != null) {
Log.d(TAG, "Saved announcement to database: " + ann.remoteId);
StorageDatabase.getInstance().updateAnnouncement(ann, null);
}
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Got notification");
sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
else {
Log.d(TAG, "No notification payload");
}
}
示例9: showNotification
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
private void showNotification(RemoteMessage remoteMessage) {
if (remoteMessage != null && remoteMessage.getNotification() != null) {
String title = getString(R.string.txt_app_name);
String message = "";
Intent intent = new Intent(this, LaunchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (remoteMessage.getNotification().getTitle() != null) {
title = remoteMessage.getNotification().getTitle();
}
if (remoteMessage.getNotification().getBody() != null) {
message = remoteMessage.getNotification().getBody();
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.drawable.notification_icon)
.setAutoCancel(true)
.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(DCSharedPreferences.getNotificationId(), notificationBuilder.build());
}
}
示例10: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@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]
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification 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.
}
示例11: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i(TAG, "DESDE: " + remoteMessage.getFrom());
if(remoteMessage.getData().size() > 0){
Log.i(TAG, "Data de mensaje: " + remoteMessage.getData());
}
if(remoteMessage.getNotification() != null){
Log.i(TAG, "Notificacion.body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
}
示例12: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Called when a message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String title;
String text;
String id;
Map<String, String> data = remoteMessage.getData();
RemoteMessage.Notification notification = remoteMessage.getNotification();
if (notification != null) {
title = notification.getTitle();
text = notification.getBody();
id = remoteMessage.getMessageId();
} else {
title = data.get("title");
text = data.get("text");
id = data.get("id");
}
if (TextUtils.isEmpty(id)) {
Random rand = new Random();
int n = rand.nextInt(50) + 1;
id = Integer.toString(n);
}
Log.i(TAG, "From: " + remoteMessage.getFrom());
Log.i(TAG, "Notification Message id: " + id);
Log.i(TAG, "Notification Message Title: " + title);
Log.i(TAG, "Notification Message Body/Text: " + text);
if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title) || (!remoteMessage.getData().isEmpty())) {
boolean showNotification = (Firebase.inBackground() || !MessagingComponent.hasNotificationsCallback())
&& (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title));
sendNotification(id, title, text, data, showNotification);
}
}
示例13: mapToNotificationBuilder
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Map a FCM remote message into a System Notification Builder mimicking the default notification format and behavior applied when the app is in background
*
* @param remoteMessage FCM remote message
* @return The notification builder configured with the notification information of the remote message
* @throws IllegalArgumentException if the remote message does not contain notification information
*/
public NotificationCompat.Builder mapToNotificationBuilder(RemoteMessage remoteMessage) throws IllegalArgumentException {
RemoteMessage.Notification fcmNotification = remoteMessage.getNotification();
if (fcmNotification == null)
throw new IllegalArgumentException(ErrorMessages.NO_NOTIFICATION_MSG);
String body = parseBody(fcmNotification);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(parseTitle(fcmNotification))
.setContentText(body)
.setStyle(new NotificationCompat.BigTextStyle().bigText(body))
.setSmallIcon(parseIcon(fcmNotification))
.setAutoCancel(true);
Integer color;
if ((color = parseColor(fcmNotification)) != null) {
builder.setColor(color);
}
int soundFileResId;
if (fcmNotification.getSound() != null &&
!fcmNotification.getSound().equals("default") &&
(soundFileResId = context.getResources().getIdentifier(fcmNotification.getSound(), "raw", context.getPackageName())) != 0) {
builder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + soundFileResId));
} else if (fcmNotification.getSound() != null) {
builder.setDefaults(Notification.DEFAULT_SOUND);
}
builder.setContentIntent(createNotificationPendingItent(remoteMessage));
return builder;
}
示例14: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@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]
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
sendNotification(remoteMessage);
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Logger.d("Message data payload: " + remoteMessage.getData());
if (/* Check if data needs to be processed by long running job */ true) {
// For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
scheduleJob();
} else {
// Handle message within 10 seconds
handleNow();
}
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Logger.d("Message Notification 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.
}
示例15: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@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]
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification 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.
sendNotification(remoteMessage.getData().get("message"));
}