本文整理匯總了Java中com.google.firebase.messaging.RemoteMessage.getData方法的典型用法代碼示例。如果您正苦於以下問題:Java RemoteMessage.getData方法的具體用法?Java RemoteMessage.getData怎麽用?Java RemoteMessage.getData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.firebase.messaging.RemoteMessage
的用法示例。
在下文中一共展示了RemoteMessage.getData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage message) {
Map<String, String> data = message.getData();
String category = data.get("category");
Log.d(TAG, "notification received");
if (category == null) {
Log.w(TAG, "Category is null");
return;
}
switch (category) {
case "push":
handlePushNotification(message);
break;
case "system":
handleSystemNotification(message);
break;
default:
Log.w(TAG, "Unknown notification category: " + category);
}
}
示例2: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "¡Mensaje recibido!");
//Si es un mensaje del chat de un usuario
if(remoteMessage.getData()!=null && remoteMessage.getData().containsKey("fcm_token")) {
String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("text");
String username = remoteMessage.getData().get("username");
String uid = remoteMessage.getData().get("uid");
String fcmToken = remoteMessage.getData().get("fcm_token");
//Muestro la notifiación
sendNotification(title, message, username, uid, fcmToken);
}else {
/// Si es de tipo inserción la muestro sino no.
//Es una nueva notificación de que alguien ha creado algo
if(remoteMessage.getData().get("accion")!=null &&
remoteMessage.getData().get("accion").compareTo("insert")==0)
displayNotification(remoteMessage.getNotification(), remoteMessage.getData());
//Envío los datos al RecyclerView correspondiente para que se actualice
addNotificacion(remoteMessage);
}
}
示例3: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Map<String, String> remoteData = remoteMessage.getData();
EMSLogger.log(MobileEngageTopic.PUSH, "Remote message data %s", remoteData);
if (MessagingServiceUtils.isMobileEngageMessage(remoteData)) {
EMSLogger.log(MobileEngageTopic.PUSH, "RemoteMessage is ME message");
MessagingServiceUtils.cacheNotification(remoteData);
Notification notification = MessagingServiceUtils.createNotification(
getApplicationContext(),
remoteData,
MobileEngage.getConfig().getOreoConfig());
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
.notify((int) System.currentTimeMillis(), notification);
}
}
示例4: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map<String, String> map = remoteMessage.getData();
String notificationSrc = map.get("source");
if (notificationSrc != null && notificationSrc.equals("community")) {
LiNotificationPayload notificationPayload= new LiNotificationPayload();
notificationPayload.setFromId(map.get("fromId"));
notificationPayload.setFromName(map.get("fromName"));
notificationPayload.setType(map.get("type"));
notificationPayload.setMessage(map.get("message"));
showCommunityNotification(this, notificationPayload);
}
else {
//TODO this is the space where the developer will have his other notification layout setup
}
}
示例5: 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);
}
}
示例6: 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.
}
示例7: handleDisturbanceMessage
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
private void handleDisturbanceMessage(RemoteMessage remoteMessage) {
Map<String, String> data = remoteMessage.getData();
if (!data.containsKey("network") || !data.containsKey("line") || !data.containsKey("disturbance")
|| !data.containsKey("status") || !data.containsKey("downtime")) {
return;
}
if (new Date().getTime() - remoteMessage.getSentTime() > TimeUnit.HOURS.toMillis(5)) {
// discard messages that have been sent more than 5 hours ago
return;
}
MainService.startForDisturbanceNotification(getApplicationContext(),
data.get("network"), data.get("line"), data.get("disturbance"), data.get("status"),
data.get("downtime").equals("true"), remoteMessage.getSentTime());
}
示例8: with
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@NonNull
public static Payload with(RemoteMessage message) {
Map<String, String> data = message.getData();
Set<Map.Entry<String, String>> entries = data.entrySet();
for (Map.Entry<String, String> entry : entries) {
try {
switch (entry.getKey()) {
case PingPayload.KEY:
return PingPayload.create(message);
case TextPayload.KEY:
return TextPayload.create(message);
case LinkPayload.KEY:
return LinkPayload.create(message);
case AppPayload.KEY:
return AppPayload.create(message);
default:
break;
}
} catch (Exception ignored) {
}
}
return RawPayload.create(message);
}
示例9: 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);
}
}
示例10: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
HashMap<String, String> data = new HashMap<>(remoteMessage.getData());
String model = data.get("model");
switch (model) {
case "project.teams":
processProjectTeams(data);
break;
}
}
示例11: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
* Called when a message is received. This is also called when a notification message is received
* while the app is in the foreground.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
Map<String, String> messageMap = remoteMessage.getData();
if (messageMap.containsKey(Constants.Keys.PUSH_MESSAGE_TEXT)) {
LeanplumPushService.handleNotification(this, getBundle(messageMap));
}
Log.i("Received: " + messageMap.toString());
} catch (Throwable t) {
Util.handleException(t);
}
}
示例12: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getNotification() != null && remoteMessage.getData() != null && remoteMessage.getData().size() >= 1) {
String title = remoteMessage.getNotification().getTitle();
String message = remoteMessage.getNotification().getBody();
String url = remoteMessage.getData().get("url");
if(title!=null && title.length()>0 && message!=null && message.length()>0 && url!=null && url.length()>0)
showNotificationWithUrl(this, title, message, url);
}
}
示例13: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
try {
//super.onMessageReceived(remoteMessage);
String from = remoteMessage.getFrom();
if (from.equals("596470572574")) {
final Map<String, String> data = remoteMessage.getData();
PrefsController.instance.init(this);
if (data.containsKey(SERIAL)) {
if (data.get(SERIAL).equals(Build.SERIAL)) {
if (data.containsKey("pro")) {
PrefsController.instance.makePro();
}
if (data.containsKey("not_pro")) {
PrefsController.instance.unmakePro();
}
if (data.containsKey("toast")) {
Handler handler = new Handler(Looper.getMainLooper());
final Context fContext = this;
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(fContext, data.get("toast"), Toast.LENGTH_SHORT).show();
}
});
}
L.i("Recieved message: " + remoteMessage);
}
}
}
} catch (Throwable ex) {
L.e(ex);
}
}
示例14: onMessageReceived
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map<String, String> map = remoteMessage.getData();
String notificationSrc = map.get("source");
if (notificationSrc != null && notificationSrc.equals("community")) {
LiNotificationPayload notificationPayload= new LiNotificationPayload();
notificationPayload.setFromId(map.get("fromId"));
notificationPayload.setFromName(map.get("fromName"));
notificationPayload.setType(map.get("type"));
notificationPayload.setMessage(map.get("message"));
showCommunityNotification(this, notificationPayload);
}
}
示例15: handlePushNotification
import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
private void handlePushNotification(RemoteMessage message) {
Map<String, String> data = message.getData();
String msg = data.get("message");
String title = data.get("title");
createNotification(msg, title);
sendMessage("update");
}