com.google.firebase.messaging.RemoteMessage Java Examples
The following examples show how to use
com.google.firebase.messaging.RemoteMessage.
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: MyFirebaseMessagingService.java From stitch-examples with Apache License 2.0 | 6 votes |
@Override public void onMessageReceived(RemoteMessage message) { RemoteMessage.Notification notification = message.getNotification(); if (notification == null) { return; } // By default, notifications will only appear if the app is in the background. // Create a new notification here to show in case the app is in the foreground. Notification.Builder notificationBuilder; NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (android.os.Build.VERSION.SDK_INT >= 26) { notificationBuilder = new Notification.Builder(getApplicationContext(), "channel_id"); } else { notificationBuilder = new Notification.Builder(getApplicationContext()); } notificationBuilder.setContentTitle(notification.getTitle()) .setContentText(notification.getBody()) .setSmallIcon(R.mipmap.ic_launcher); notificationBuilder.setAutoCancel(true) .setDefaults(NotificationCompat.DEFAULT_ALL); manager.notify(1, notificationBuilder.build()); }
Example #3
Source File: MyFirebaseMessagingService.java From grblcontroller with GNU General Public License v3.0 | 6 votes |
private void notificationBugTracker(RemoteMessage remoteMessage){ String notificationTitle = remoteMessage.getData().get(KEY_NOTIFICATION_TITLE); String notificationMessage = remoteMessage.getData().get(KEY_NOTIFICATION_MESSAGE); String categoryName = remoteMessage.getData().get(KEY_CATEGORY_NAME); String categoryValue = remoteMessage.getData().get(KEY_CATEGORY_VALUE); if(notificationTitle == null || notificationMessage == null || categoryName == null || categoryValue == null) return; NotificationHelper notificationHelper = new NotificationHelper(this); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(categoryValue)); final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); notificationHelper.getNotificationGeneral(notificationTitle, notificationMessage, pendingIntent); saveNotification(remoteMessage); }
Example #4
Source File: NotificationManager.java From weMessage with GNU Affero General Public License v3.0 | 6 votes |
private void performErroredNotification(Context context, RemoteMessage remoteMessage){ NotificationCompat.Builder builder; android.app.NotificationManager notificationManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder = new NotificationCompat.Builder(context, weMessage.NOTIFICATION_CHANNEL_NAME); } else { builder = new NotificationCompat.Builder(context); builder.setVibrate(new long[]{1000, 1000}) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } Notification notification = builder .setContentTitle(context.getString(R.string.notification_error)) .setContentText(context.getString(R.string.notification_error_body)) .setSmallIcon(R.drawable.ic_app_notification_white_small) .setWhen(remoteMessage.getSentTime()) .setAutoCancel(true) .build(); notificationManager.cancel(ERRORED_NOTIFICATION_TAG); notificationManager.notify(ERRORED_NOTIFICATION_TAG, notification); }
Example #5
Source File: MyFirebaseMessagingService.java From stitch-android-sdk with Apache License 2.0 | 6 votes |
@Override public void onMessageReceived(final RemoteMessage remoteMessage) { final Map<String, String> data = remoteMessage.getData(); final Document stitchData; if (data.containsKey(STITCH_DATA)) { stitchData = Document.parse(data.get(STITCH_DATA)); } else { stitchData = null; } final String appId = data.containsKey(STITCH_APP_ID) ? data.get(STITCH_APP_ID) : ""; if (stitchData == null) { Log.i(TAG, String.format("received an FCM message: %s", remoteMessage.toString())); } else { Log.i(TAG, String.format( "received an FCM message from Stitch(%s): %s", appId, stitchData.toString())); } }
Example #6
Source File: MyMessagingService.java From Pharmacy-Android with GNU General Public License v3.0 | 6 votes |
private void createOrderUpdateNotification(RemoteMessage.Notification notification, Map<String, String> data) { Context context = getBaseContext(); String orderId = data.get("order_id"); String type = data.get("type"); Intent orderDetailIntent = OrderDetailActivity.getInstanceByOrderId(context, orderId); int requestID = (int) System.currentTimeMillis(); //unique requestID to differentiate between various notification with same NotifId int flags = PendingIntent.FLAG_CANCEL_CURRENT; // cancel old intent and create new one PendingIntent pIntent = PendingIntent.getActivity(this, requestID, orderDetailIntent, flags); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(notification.getTitle()) .setContentText(notification.getBody()) .setSound(alarmSound) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) .setContentIntent(pIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(orderId,ORDER_UPDATE_NOTIFICATION_ID, mBuilder.build()); }
Example #7
Source File: MyFirebaseMessagingService.java From Doctorave with MIT License | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { String notificationTitle = null,notificationTime = null ,notificationBody = null; // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { notificationTitle = remoteMessage.getNotification().getTitle(); notificationBody = remoteMessage.getNotification().getBody(); } if(notificationBody.equals(doctorPreference.getUserPushId(getApplicationContext()))){ sendNotification(notificationTitle); } }
Example #8
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 #9
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 #10
Source File: MessagingService.java From react-native-fcm with MIT License | 6 votes |
public void buildLocalNotification(RemoteMessage remoteMessage) { if(remoteMessage.getData() == null){ return; } Map<String, String> data = remoteMessage.getData(); String customNotification = data.get("custom_notification"); if(customNotification != null){ try { Bundle bundle = BundleJSONConverter.convertToBundle(new JSONObject(customNotification)); FIRLocalMessagingHelper helper = new FIRLocalMessagingHelper(this.getApplication()); helper.sendNotification(bundle); } catch (JSONException e) { e.printStackTrace(); } } }
Example #11
Source File: HaFirebaseMessagingService.java From homeassist with Apache License 2.0 | 6 votes |
/** * 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) { // TODO(developer): Handle FCM messages here. // If the application is in the foreground handle both data and notification messages here. // 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. Log.d("YouQi", "getFrom: " + remoteMessage.getFrom()); Log.d("YouQi", "getTo: " + remoteMessage.getTo()); Log.d("YouQi", "getNotification: " + remoteMessage.getNotification()); Log.d("YouQi", "getNotification getBody: " + remoteMessage.getNotification().getBody()); Log.d("YouQi", "getNotification getTitle: " + remoteMessage.getNotification().getTitle()); Log.d("YouQi", "getSentTime: " + remoteMessage.getSentTime()); Log.d("YouQi", "getMessageType: " + remoteMessage.getMessageType()); //Log.d("YouQi", "Notification Message Body: " + remoteMessage.getNotification().getBody()); //sendNotification(remoteMessage.getNotification().getBody()); }
Example #12
Source File: AVFirebaseMessagingService.java From java-unified-sdk with Apache License 2.0 | 6 votes |
/** * FCM 有两种消息:通知消息与数据消息。 * 通知消息 -- 就是普通的通知栏消息,应用在后台的时候,通知消息会直接显示在通知栏,默认情况下, * 用户点按通知即可打开应用启动器(通知消息附带的参数在 Bundle 内),我们无法处理。 * * 数据消息 -- 类似于其他厂商的「透传消息」。应用在前台的时候,数据消息直接发送到应用内,应用层通过这一接口进行响应。 * * @param remoteMessage */ @Override public void onMessageReceived(RemoteMessage remoteMessage) { Map<String, String> data = remoteMessage.getData(); if (null == data) { return; } LOGGER.d("received message from: " + remoteMessage.getFrom() + ", payload: " + data.toString()); try { JSONObject jsonObject = JSON.parseObject(data.get("payload")); if (null != jsonObject) { String channel = jsonObject.getString("_channel"); String action = jsonObject.getString("action"); AndroidNotificationManager androidNotificationManager = AndroidNotificationManager.getInstance(); androidNotificationManager.processGcmMessage(channel, action, jsonObject.toJSONString()); } } catch (Exception ex) { LOGGER.e("failed to parse push data.", ex); } }
Example #13
Source File: MyFirebaseMessagingService.java From LNMOnlineAndroidSample with Apache License 2.0 | 6 votes |
@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()); } } }
Example #14
Source File: FirebaseMessagingPlugin.java From cordova-plugin-firebase-messaging with MIT License | 6 votes |
static void sendNotification(RemoteMessage remoteMessage) { JSONObject notificationData = new JSONObject(remoteMessage.getData()); RemoteMessage.Notification notification = remoteMessage.getNotification(); try { if (notification != null) { notificationData.put("gcm", toJSON(notification)); } notificationData.put("google.message_id", remoteMessage.getMessageId()); notificationData.put("google.sent_time", remoteMessage.getSentTime()); if (instance != null) { CallbackContext callbackContext = instance.isBackground ? instance.backgroundCallback : instance.foregroundCallback; instance.sendNotification(notificationData, callbackContext); } } catch (JSONException e) { Log.e(TAG, "sendNotification", e); } }
Example #15
Source File: FcmMessageListenerService.java From clevertap-android-sdk with MIT License | 6 votes |
@Override public void onMessageReceived(RemoteMessage message){ try { if (message.getData().size() > 0) { Bundle extras = new Bundle(); for (Map.Entry<String, String> entry : message.getData().entrySet()) { extras.putString(entry.getKey(), entry.getValue()); } NotificationInfo info = CleverTapAPI.getNotificationInfo(extras); if (info.fromCleverTap) { Logger.d("FcmMessageListenerService received notification from CleverTap: " + extras.toString()); CleverTapAPI.createNotification(getApplicationContext(), extras); } } } catch (Throwable t) { Logger.d("Error parsing FCM message", t); } }
Example #16
Source File: QiscusFirebaseMessagingUtil.java From qiscus-sdk-android with Apache License 2.0 | 6 votes |
/** * Handle remote message from FCM to display push notification * * @param remoteMessage The message from firebase * @return true if the message is for Qiscus SDK, false if the message is not for Qiscus SDK */ public static boolean handleMessageReceived(RemoteMessage remoteMessage) { if (remoteMessage.getData().containsKey("qiscus_sdk")) { if (QiscusCore.hasSetupUser()) { if (!QiscusPusherApi.getInstance().isConnected()) { QiscusPusherApi.getInstance().restartConnection(); } if (remoteMessage.getData().containsKey("payload")) { if (remoteMessage.getData().get("qiscus_sdk").equals("post_comment")) { handlePostCommentEvent(remoteMessage); } else if (remoteMessage.getData().get("qiscus_sdk").equals("delete_message")) { handleDeleteCommentsEvent(remoteMessage); } else if (remoteMessage.getData().get("qiscus_sdk").equals("clear_room")) { handleClearComments(remoteMessage); } } } return true; } return false; }
Example #17
Source File: FirebaseMessagingPluginService.java From cordova-plugin-firebase-messaging with MIT License | 6 votes |
private void showAlert(RemoteMessage.Notification notification) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getNotificationChannel(notification)) .setSound(getNotificationSound(notification.getSound())) .setContentTitle(notification.getTitle()) .setContentText(notification.getBody()) .setGroup(notification.getTag()) .setSmallIcon(defaultNotificationIcon) .setColor(defaultNotificationColor) // must set priority to make sure forceShow works properly .setPriority(1); notificationManager.notify(0, builder.build()); // dismiss notification to hide icon from status bar automatically new Handler(getMainLooper()).postDelayed(new Runnable() { @Override public void run() { notificationManager.cancel(0); } }, 3000); }
Example #18
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 #19
Source File: CountlyMessagingService.java From countly-sdk-cordova with MIT License | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); Log.d(TAG, "got new message: " + remoteMessage.getData()); // decode message data and extract meaningful information from it: title, body, badge, etc. CountlyPush.Message message = CountlyPush.decodeMessage(remoteMessage.getData()); if (message != null && message.has("typ")) { // custom handling only for messages with specific "typ" keys message.recordAction(getApplicationContext()); return; } Intent notificationIntent = null;//new Intent(getApplicationContext(), MainActivity.class); Boolean result = CountlyPush.displayMessage(getApplicationContext(), message, getApplicationContext().getApplicationInfo().icon, notificationIntent); if (result == null) { Log.i(TAG, "Message wasn't sent from Countly server, so it cannot be handled by Countly SDK"); } else if (result) { Log.i(TAG, "Message was handled by Countly SDK"); } else { Log.i(TAG, "Message wasn't handled by Countly SDK because API level is too low for Notification support or because currentActivity is null (not enough lifecycle method calls)"); } }
Example #20
Source File: VoiceFirebaseMessagingService.java From cordova-plugin-twiliovoicesdk with MIT License | 6 votes |
/** * Called when message is received. * * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. */ @Override public void onMessageReceived(RemoteMessage remoteMessage) { Log.d(TAG, "Received onMessageReceived()"); Log.d(TAG, "Bundle data: " + remoteMessage.getData()); Log.d(TAG, "From: " + remoteMessage.getFrom()); // Check if message contains a data payload. if (remoteMessage.getData().size() > 0) { Map<String, String> data = remoteMessage.getData(); final int notificationId = (int) (System.currentTimeMillis() % Integer.MAX_VALUE); Voice.handleMessage(data, new MessageListener() { @Override public void onCallInvite(CallInvite callInvite) { VoiceFirebaseMessagingService.this.notify(callInvite, notificationId); VoiceFirebaseMessagingService.this.sendCallInviteToPlugin(callInvite, notificationId); } @Override public void onCancelledCallInvite(@NonNull CancelledCallInvite cancelledCallInvite) { Log.e(TAG, cancelledCallInvite.getFrom()); } }); } }
Example #21
Source File: CountlyMessagingService.java From countly-sdk-cordova with MIT License | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); Log.d(TAG, "got new message: " + remoteMessage.getData()); // decode message data and extract meaningful information from it: title, body, badge, etc. CountlyPush.Message message = CountlyPush.decodeMessage(remoteMessage.getData()); if (message != null && message.has("typ")) { // custom handling only for messages with specific "typ" keys message.recordAction(getApplicationContext()); return; } Intent notificationIntent = null;//new Intent(getApplicationContext(), MainActivity.class); Boolean result = CountlyPush.displayMessage(getApplicationContext(), message, getApplicationContext().getApplicationInfo().icon, notificationIntent); if (result == null) { Log.i(TAG, "Message wasn't sent from Countly server, so it cannot be handled by Countly SDK"); } else if (result) { Log.i(TAG, "Message was handled by Countly SDK"); } else { Log.i(TAG, "Message wasn't handled by Countly SDK because API level is too low for Notification support or because currentActivity is null (not enough lifecycle method calls)"); } }
Example #22
Source File: MessagingService.java From mini-hacks with MIT License | 6 votes |
@Override public void onMessageReceived(final RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { @Override public void run() { Foreground foreground = Foreground.get(getApplicationContext()); if (foreground.isBackground()) { Log.d(Application.TAG, "From: " + remoteMessage.getFrom()); Toast.makeText(getApplicationContext(), "Server ping - sync down!", Toast.LENGTH_LONG).show(); BackgroundSync backgroundSync = new BackgroundSync(); backgroundSync.execute(); } } }, 2000); }
Example #23
Source File: FirebaseMessagingService.java From rcloneExplorer with MIT License | 6 votes |
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); setNotificationChannel(); Uri uri = Uri.parse(getString(R.string.app_latest_release_url)); Intent intent = new Intent(Intent.ACTION_VIEW, uri); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(getString(R.string.app_update_notification_title)) .setPriority(NotificationCompat.PRIORITY_LOW) .setContentIntent(pendingIntent) .setAutoCancel(true); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(33, builder.build()); }
Example #24
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 #25
Source File: MyFirebaseMessagingService.java From GcmForMojo with GNU General Public License v3.0 | 5 votes |
/** * 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 //handler = new Handler(Looper.getMainLooper()); // 使用应用的主消息循环 // Check if message contains a notification payload. if (remoteMessage.getNotification() != null) { Log.d(MYTAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); } if (remoteMessage.getData().size() > 0) { if(!remoteMessage.getData().containsKey("isAt")) remoteMessage.getData().put("isAt","0"); if(!remoteMessage.getData().containsKey("senderType")) remoteMessage.getData().put("senderType","1"); //SharedPreferences Settings = getSharedPreferences(PREF, Context.MODE_PRIVATE); String tokenSender = mySettings.getString("push_type","GCM"); if(tokenSender.equals("GCM")) { Log.d(MYTAG, "谷歌推送: " + remoteMessage.getData()); MessageUtil.MessageUtilDo(getApplicationContext(),remoteMessage.getData().get("msgId"),remoteMessage.getData().get("type"),remoteMessage.getData().get("senderType"),remoteMessage.getData().get("title"),remoteMessage.getData().get("message"),remoteMessage.getData().get("isAt")); } } }
Example #26
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 #27
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 #28
Source File: MyFirebaseMessagingService.java From BOMBitUP with GNU General Public License v3.0 | 5 votes |
/** * 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()); 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) { 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. }
Example #29
Source File: MyFirebaseMessagingService.java From JumpGo with Mozilla Public License 2.0 | 5 votes |
/** * 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()); 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) { 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. }
Example #30
Source File: MainActivity.java From snippets-android with Apache License 2.0 | 5 votes |
public void deviceGroupUpstream() { // [START fcm_device_group_upstream] String to = "a_unique_key"; // the notification key AtomicInteger msgId = new AtomicInteger(); FirebaseMessaging.getInstance().send(new RemoteMessage.Builder(to) .setMessageId(String.valueOf(msgId.get())) .addData("hello", "world") .build()); // [END fcm_device_group_upstream] }