本文整理匯總了Java中com.google.firebase.messaging.RemoteMessage.Notification方法的典型用法代碼示例。如果您正苦於以下問題:Java RemoteMessage.Notification方法的具體用法?Java RemoteMessage.Notification怎麽用?Java RemoteMessage.Notification使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.firebase.messaging.RemoteMessage
的用法示例。
在下文中一共展示了RemoteMessage.Notification方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: displayNotification
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Muestra que ha habido una nueva notificación
* @param notification
* @param data
*/
private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("notificacion","notificacion");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(notification.getTitle())
.setContentText(notification.getBody())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setSmallIcon(R.mipmap.ic_launch)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
示例2: sendNotification
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(RemoteMessage.Notification messageBody) {
System.out.println("SEND NOTIFICATION CALLED");
Intent intent = new Intent(this, SplashActivity.class);
System.out.println(messageBody.getBody());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(messageBody.getTitle())
.setContentText(messageBody.getBody())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
示例3: parseColor
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Nullable
private Integer parseColor(RemoteMessage.Notification fcmNotification) {
String notificationColor = fcmNotification.getColor();
Integer color = null;
if (notificationColor != null) {
try {
color = Color.parseColor(notificationColor);
} catch (IllegalArgumentException ignore) {
}
}
if (color == null) {
int colorResId = getResourceIdFromApplicationMetadata("com.google.firebase.messaging.default_notification_color");
if (colorResId != 0)
color = ContextCompat.getColor(context, colorResId);
}
return color;
}
示例4: 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);
}
}
示例5: notify
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Fire a system tray notification from the FCM message mimicking the default notification format and behavior applied when the app is in background
*
* @param remoteMessage FCM remote message
* @throws IllegalArgumentException if the remote message does not contain notification information
*/
public void notify(RemoteMessage remoteMessage) throws IllegalArgumentException {
RemoteMessage.Notification fcmNotification = remoteMessage.getNotification();
if (fcmNotification == null)
throw new IllegalArgumentException(ErrorMessages.NO_NOTIFICATION_MSG);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String tag = fcmNotification.getTag();
notificationManager.notify(tag, tag == null ? remoteMessage.getMessageId().hashCode() : 0, new RemoteMessageToNotificationMapper(context).map(remoteMessage));
}
示例6: 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;
}
示例7: parseTitle
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
private String parseTitle(RemoteMessage.Notification fcmNotification) {
String title = fcmNotification.getTitle();
if (title == null) {
String titleLocalizationKey = fcmNotification.getTitleLocalizationKey();
if (titleLocalizationKey != null) {
title = getLocalizedString(titleLocalizationKey, fcmNotification.getTitleLocalizationArgs());
}
if (title == null) {
title = getApplicationName();
}
}
return title;
}
示例8: parseBody
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Nullable
private String parseBody(RemoteMessage.Notification fcmNotification) {
String body = fcmNotification.getBody();
if (body == null) {
String bodyLocalizationKey = fcmNotification.getBodyLocalizationKey();
if (bodyLocalizationKey != null) {
body = getLocalizedString(bodyLocalizationKey, fcmNotification.getBodyLocalizationArgs());
}
}
return body;
}
示例9: parseIcon
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
private int parseIcon(RemoteMessage.Notification fcmNotification) {
String notificationIcon = fcmNotification.getIcon();
int iconResId = 0;
if (notificationIcon != null) {
iconResId = context.getResources().getIdentifier(notificationIcon, "drawable", context.getPackageName());
}
if (iconResId == 0) {
iconResId = getResourceIdFromApplicationMetadata("com.google.firebase.messaging.default_notification_icon");
if (iconResId == 0)
iconResId = getApplicationIconResId();
}
return iconResId;
}