Java Code Examples for com.google.firebase.messaging.RemoteMessage#getData()
The following examples show how to use
com.google.firebase.messaging.RemoteMessage#getData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyFirebaseMessagingService.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 8 votes |
@Override public void onMessageReceived(RemoteMessage message) { RemoteMessage.Notification notification = message.getNotification(); if (notification != null) { String title = notification.getTitle(); String body = notification.getBody(); // Post your own notification using NotificationCompat.Builder // or send the information to your UI } // Listing 11-31: Receiving data using the Firebase Messaging Service Map<String,String> data = message.getData(); if (data != null) { String value = data.get("your_key"); // Post your own Notification using NotificationCompat.Builder // or send the information to your UI } }
Example 2
Source File: NotificationData.java From azure-notificationhubs-android with Apache License 2.0 | 6 votes |
public NotificationData(RemoteMessage remoteMessage) { Map<String, String> remoteMessageData = remoteMessage.getData(); this.message = remoteMessageData.get("message"); this.title = remoteMessageData.getOrDefault("title", "Default notification title"); this.badgeCount = remoteMessageData.containsKey("badgeCount") ? Integer.parseInt(remoteMessageData.get("badgeCount")) : null; this.customAction = remoteMessageData.containsKey("customAction") ? parseCustomAction(remoteMessageData.get("customAction")) : null; this.customAudio = remoteMessageData.containsKey("customAudio") ? parseCustomAudio(remoteMessageData.get("customAudio")) : null; this.timeoutMs = remoteMessageData.containsKey("timeoutMs") ? Integer.parseInt(remoteMessageData.get("timeoutMs")) : null; this.messageSize = remoteMessageData.containsKey("messageSize") ? parseMessageSize(remoteMessageData.get("messageSize")): null; this.includePicture = Boolean.parseBoolean(remoteMessageData.getOrDefault("includePicture", "false")); }
Example 3
Source File: MyFirebaseMessagingService.java From BusyBox with Apache License 2.0 | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { Map<String, String> dataMap = remoteMessage.getData(); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_status_bar_icon) .setContentTitle(dataMap.get(TITLE_KEY)) .setContentText(dataMap.get(MESSAGE_KEY)) .setAutoCancel(true) .setSound(defaultSoundUri); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = MainActivity.linkIntent(this, dataMap.get(URI_KEY)); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); notificationBuilder.setContentIntent(pending); notificationManager.notify(0, notificationBuilder.build()); }
Example 4
Source File: BsFirebaseMessagingService.java From buddysearch with Apache License 2.0 | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { Map<String, String> data = remoteMessage.getData(); if (data == null) { return; } String senderId = data.get(FirebaseMessageEntityStore.KEY_FCM_SENDER_ID); if (TextUtils.isEmpty(senderId)) { return; } String text = data.get(FirebaseMessageEntityStore.KEY_FCM_TEXT); sendNotification(senderId, text); getUser.execute(senderId, new DefaultSubscriber<UserDto>(null) { @Override public void onNext(UserDto userDto) { super.onNext(userDto); updateNotification(senderId, StringUtil.concatLinearly(" ", userDto.getFirstName(), userDto.getLastName()), text, false); } }); }
Example 5
Source File: MessagingService.java From react-native-fcm with MIT License | 6 votes |
public void handleBadge(RemoteMessage remoteMessage) { BadgeHelper badgeHelper = new BadgeHelper(this); if (remoteMessage.getData() == null) { return; } Map data = remoteMessage.getData(); if (data.get("badge") == null) { return; } try { int badgeCount = Integer.parseInt((String)data.get("badge")); badgeHelper.setBadgeCount(badgeCount); } catch (Exception e) { Log.e(TAG, "Badge count needs to be an integer", e); } }
Example 6
Source File: NotifyFirebaseMessagingService.java From video-quickstart-android with MIT License | 6 votes |
/** * Called when a message is received. * * @param message The remote message, containing from, and message data as key/value pairs. */ @Override public void onMessageReceived(RemoteMessage message) { /* * The Notify service adds the message body to the remote message data so that we can * show a simple notification. */ Map<String,String> messageData = message.getData(); String title = messageData.get(NOTIFY_TITLE_KEY); String body = messageData.get(NOTIFY_BODY_KEY); Invite invite = new Invite(messageData.get(NOTIFY_INVITE_FROM_IDENTITY_KEY), messageData.get(NOTIFY_INVITE_ROOM_NAME_KEY)); Log.d(TAG, "From: " + invite.fromIdentity); Log.d(TAG, "Room Name: " + invite.roomName); Log.d(TAG, "Title: " + title); Log.d(TAG, "Body: " + body); showNotification(title, body, invite.roomName); broadcastVideoNotification(title, invite.roomName); }
Example 7
Source File: KaliumMessagingService.java From natrium-android-wallet with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(this); if (sharedPreferencesUtil.getLanguage() != AvailableLanguage.DEFAULT) { Locale locale = new Locale(sharedPreferencesUtil.getLanguage().getLocaleString()); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); } if (remoteMessage.getData() != null && sharedPreferencesUtil.isBackgrounded() && sharedPreferencesUtil.getNotificationSetting() != NotificationOption.OFF) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { sendNotification(remoteMessage); } else { sendNotificationLegacy(remoteMessage); } } }
Example 8
Source File: MyFirebaseMessagingService.java From social-app-android with Apache License 2.0 | 5 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { if (remoteMessage.getData() != null && remoteMessage.getData().get(ACTION_TYPE_KEY) != null) { handleRemoteMessage(remoteMessage); } else { LogUtil.logError(TAG, "onMessageReceived()", new RuntimeException("FCM remoteMessage doesn't contains Action Type")); } }
Example 9
Source File: LeanplumPushFirebaseMessagingService.java From Leanplum-Android-SDK with Apache License 2.0 | 5 votes |
/** * 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(getApplicationContext(), getBundle(messageMap)); } Log.i("Received: " + messageMap.toString()); } catch (Throwable t) { Util.handleException(t); } }
Example 10
Source File: MyFirebaseMessagingService.java From WaniKani-for-Android with GNU General Public License v3.0 | 5 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); Map<String, String> data = remoteMessage.getData(); int id = Integer.valueOf(data.get(Notification.DATA_NOTIFICATION_ID)); String title = data.get(Notification.DATA_NOTIFICATION_TITLE); String shortText = data.get(Notification.DATA_NOTIFICATION_SHORT_TEXT); String text = data.get(Notification.DATA_NOTIFICATION_TEXT); String image = data.get(Notification.DATA_NOTIFICATION_IMAGE); String actionUrl = data.get(Notification.DATA_NOTIFICATION_ACTION_URL); String actionText = data.get(Notification.DATA_NOTIFICATION_ACTION_TEXT); DatabaseManager.saveNotification(new Notification( id, title, shortText, text, image, actionUrl, actionText, false )); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BroadcastIntents.NOTIFICATION())); } }
Example 11
Source File: PushMessageReceiver.java From Conversations with GNU General Public License v3.0 | 5 votes |
@Override public void onMessageReceived(RemoteMessage message) { if (!EventReceiver.hasEnabledAccounts(this)) { Log.d(Config.LOGTAG,"PushMessageReceiver ignored message because no accounts are enabled"); return; } final Map<String, String> data = message.getData(); final Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_FCM_MESSAGE_RECEIVED); intent.putExtra("account", data.get("account")); Compatibility.startService(this, intent); }
Example 12
Source File: TelephotoFirebaseMessagingService.java From Telephoto with Apache License 2.0 | 5 votes |
@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); } }
Example 13
Source File: MyFirebaseMessagingService.java From kute with Apache License 2.0 | 5 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { //************ CHECK TO SEE IF THERE IS A DATA MESSAGE ******************* if(remoteMessage.getData().size() >0) { String messagebody; Log.i(TAG, "Message data payload: " + remoteMessage.getData()); try { JSONObject data=new JSONObject(remoteMessage.getData()); processDataMessage(data); //imageurl=data.getString("image"); } catch (Exception e) { Log.d("Json Exception",e.toString()); messagebody=null; //imageurl=null; } //sendBigNotification(messagebody); } //***************** CHECK TO SEE IF THERE IS A NOTIFICATION *********************// if(remoteMessage.getNotification()!=null) { Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); Intent intent = new Intent(this, Main.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); sendBigNotification(remoteMessage.getNotification().getBody(),pendingIntent); } }
Example 14
Source File: MyFirebaseMessagingService.java From social-app-android with Apache License 2.0 | 5 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { if (remoteMessage.getData() != null && remoteMessage.getData().get(ACTION_TYPE_KEY) != null) { handleRemoteMessage(remoteMessage); } else { LogUtil.logError(TAG, "onMessageReceived()", new RuntimeException("FCM remoteMessage doesn't contains Action Type")); } }
Example 15
Source File: NotificationService.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { if (isFirstMessage) { if (remoteMessage.getData().size() > 0) { Map<String, String> date = remoteMessage.getData(); if (date.containsKey(ROOM_ID) && date.containsKey(MESSAGE_ID)) { // type of dataMap is messageId roomId type loc_key loc_args Long roomId = Long.parseLong(date.get(ROOM_ID)); Long messageId = Long.parseLong(date.get(MESSAGE_ID)); G.handler.postDelayed(new Runnable() { @Override public void run() { new RequestClientGetRoomMessage().clientGetRoomMessage(roomId, messageId); } }, 2000); G.onClientGetRoomMessage = new OnClientGetRoomMessage() { @Override public void onClientGetRoomMessageResponse(ProtoGlobal.RoomMessage message) { G.onClientGetRoomMessage = null; if (date.containsKey(MESSAGE_TYPE)) { final Realm realm = Realm.getDefaultInstance(); RealmRoom room = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst(); if (room != null) { HelperNotification.getInstance().addMessage(roomId, message, room.getType(), room, realm); } realm.close(); } } }; } } isFirstMessage = false; } }
Example 16
Source File: FirebaseMessageMapper.java From mobile-messaging-sdk-android with Apache License 2.0 | 5 votes |
private static IBData getIBData(RemoteMessage remoteMessage) { String json; if (remoteMessage == null || remoteMessage.getData() == null || (json = remoteMessage.getData().get(IB_DATA_KEY)) == null) { return null; } return serializer.deserialize(json, IBData.class); }
Example 17
Source File: PushMessageReceiver.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
@Override public void onMessageReceived(RemoteMessage message) { if (!EventReceiver.hasEnabledAccounts(this)) { Log.d(Config.LOGTAG, "PushMessageReceiver ignored message because no accounts are enabled"); return; } final Map<String, String> data = message.getData(); final Intent intent = new Intent(this, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_FCM_MESSAGE_RECEIVED); intent.putExtra("account", data.get("account")); Compatibility.startService(this, intent); }
Example 18
Source File: AeroGearUPSMessageService.java From aerogear-android-push with Apache License 2.0 | 5 votes |
@Override /** * When a FCM message is received, the attached implementations of our * <code>MessageHandler</code> interface are being notified. */ public void onMessageReceived(RemoteMessage remoteMessage) { Map<String, String> messageMap = remoteMessage.getData(); Bundle message = new Bundle(); for (Map.Entry<String, String> messageMapEntry : messageMap.entrySet()) { message.putString(messageMapEntry.getKey(), messageMapEntry.getValue()); } if (checkDefaultHandler) { checkDefaultHandler = false; Bundle metaData = getMetadata(getApplicationContext()); if (metaData != null) { String defaultHandlerClassName = metaData.getString(DEFAULT_MESSAGE_HANDLER_KEY); if (defaultHandlerClassName != null) { try { Class<? extends MessageHandler> defaultHandlerClass = (Class<? extends MessageHandler>) Class.forName(defaultHandlerClassName); defaultHandler = defaultHandlerClass.newInstance(); } catch (Exception ex) { Log.e(TAG, ex.getMessage(), ex); } } } } // notity all attached MessageHandler implementations: RegistrarManager.notifyHandlers(getApplicationContext(), message, defaultHandler); }
Example 19
Source File: MessagingService.java From cordova-plugin-firebase-extended-notification with MIT License | 5 votes |
public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); if(remoteMessage.getNotification() != null || remoteMessage.getData() == null || remoteMessage.getData().get("notificationOptions") == null){ return; //does nothing } Map<String, String> originalData = remoteMessage.getData(); JSONObject options; try { // If as object options = new JSONObject(originalData.get("notificationOptions")); } catch (JSONException e1) { try { // If stringified String notificationOptions = originalData.get("notificationOptions"); if(notificationOptions == null || notificationOptions.length() < 2) { // Should not substring on small string return; } options = new JSONObject(notificationOptions.substring(1, notificationOptions.length() - 1)); } catch (JSONException e2) { return; //invalid json, all will be as default } } new Manager(this).showNotification(new JSONObject(originalData), options); }
Example 20
Source File: MyMessagingService.java From Pharmacy-Android with GNU General Public License v3.0 | 4 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { Timber.d("From %s", remoteMessage.getFrom()); Timber.d("Notification Message Body: %s", remoteMessage.getNotification().getBody()); // TODO: 22/5/16 Show notification on Order update Map<String, String> data = remoteMessage.getData(); RemoteMessage.Notification notification = remoteMessage.getNotification(); if (data.get("type").equals("ORDER_UPDATE")) { createOrderUpdateNotification(notification, data); } }