Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Log.d(TAG,"RECIBE EL MENSAJE");
- // 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.getNotification().getBody());
- try
- {
- Map<String, String> params = remoteMessage.getData();
- JSONObject object = new JSONObject(params);
- Log.e("JSON_OBJECT", object.toString());
- } catch(Exception ex){
- }
- 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.
- Intent intent = new Intent(this, MainActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
- NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
- notificationBuilder.setContentTitle("FCM NOTIFICATION");
- notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
- notificationBuilder.setAutoCancel(true);
- notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
- notificationBuilder.setContentIntent(pendingIntent);
- notificationBuilder.setPriority(NotificationManager.IMPORTANCE_HIGH);
- notificationBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
- NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- notificationManager.notify(0,notificationBuilder.build());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement