Java 类com.google.firebase.messaging.RemoteMessage 实例源码

项目:android-mobile-engage-sdk    文件:MobileEngageMessagingService.java   
@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);
    }
}
项目:humaniq-android    文件:FcmListenerService.java   
@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);
    }
}
项目:TFG-SmartU-La-red-social    文件:MyFirebaseMessagingService.java   
@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);
    }
}
项目:TFG-SmartU-La-red-social    文件:MyFirebaseMessagingService.java   
/**
 * 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());
}
项目:Clases-2017c1    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getData().size() > 0) {
        Boolean isLongRunningTask = this.isLongRunningTask(remoteMessage.getData());

        if (isLongRunningTask) {
            scheduleJob(remoteMessage.getData());
        } else {
            handleNow(remoteMessage.getData());
        }
    }

    if (remoteMessage.getNotification() != null) {
        sendNotification(remoteMessage.getNotification().getBody());
    }
}
项目:social-app-android    文件:MyFirebaseMessagingService.java   
private void parseCommentOrLike(RemoteMessage remoteMessage) {
    String notificationTitle = remoteMessage.getData().get(TITLE_KEY);
    String notificationBody = remoteMessage.getData().get(BODY_KEY);
    String notificationImageUrl = remoteMessage.getData().get(ICON_KEY);
    String postId = remoteMessage.getData().get(POST_ID_KEY);

    Intent backIntent = new Intent(this, MainActivity.class);
    Intent intent = new Intent(this, PostDetailsActivity.class);
    intent.putExtra(PostDetailsActivity.POST_ID_EXTRA_KEY, postId);

    Bitmap bitmap = getBitmapFromUrl(notificationImageUrl);

    sendNotification(notificationTitle, notificationBody, bitmap, intent, backIntent);

    LogUtil.logDebug(TAG, "Message Notification Body: " + remoteMessage.getData().get(BODY_KEY));
}
项目:FcmNotificationHandler    文件:RemoteMessageToNotificationMapper.java   
@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;
}
项目:social-app-android    文件:MyFirebaseMessagingService.java   
private void handleRemoteMessage(RemoteMessage remoteMessage) {
    String receivedActionType = remoteMessage.getData().get(ACTION_TYPE_KEY);
    LogUtil.logDebug(TAG, "Message Notification Action Type: " + receivedActionType);

    switch (receivedActionType) {
        case ACTION_TYPE_NEW_LIKE:
            parseCommentOrLike(remoteMessage);
            break;
        case ACTION_TYPE_NEW_COMMENT:
            parseCommentOrLike(remoteMessage);
            break;
        case ACTION_TYPE_NEW_POST:
            handleNewPostCreatedAction(remoteMessage);
            break;
    }
}
项目:BookED    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    Intent i = new Intent(this, BottomNavigation.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,0 , i ,
            PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder nb= new NotificationCompat.Builder(this);
    nb.setContentTitle("FCM Notification");
    nb.setContentText(remoteMessage.getNotification().getBody());
    nb.setAutoCancel(true);
    nb.setSmallIcon(R.mipmap.ic_launcher);
    nb.setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0,nb.build());
}
项目:gdgApp    文件:MessagingService.java   
private void handleMessage(RemoteMessage remoteMessage) {

        Intent intent = new Intent(this, FirebaseAuth.getInstance().getCurrentUser() == null ? LoginActivity.class:MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent intent1 = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);


        Uri defaultURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this,NotificationCompat.CATEGORY_MESSAGE)
                .setSmallIcon(R.drawable.gdg_notification_icon)
                .setContentTitle(remoteMessage.getNotification().getTitle())
                .setContentText(remoteMessage.getNotification().getBody())
                .setAutoCancel(true)
                .setSound(defaultURI)
                .setContentIntent(intent1);

        NotificationManager manager =  ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
        if (manager != null) {
            manager.notify(23,builder.build());
        }


    }
项目:TapIn    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
    if (remoteMessage.getData().size() > 0)
    {
        try
        {
            JSONObject json = new JSONObject(remoteMessage.getData().toString());
            sendPushNotification(json);
        }
        catch (Exception e)
        {
            Log.e(TAG, "Exception: " + e.getMessage());
        }
    }
}
项目:Android-2017    文件:FirebaseMessangingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    if (remoteMessage.getData().size() > 0) {
        // procesa los datos extra de la notificación
    }

    if (remoteMessage.getNotification() != null) {
        String title = remoteMessage.getNotification().getTitle();
        String message = remoteMessage.getNotification().getBody();
        String clickAction = remoteMessage.getNotification().getClickAction();


        Log.d(TAG, "Title: " + title);
        Log.d(TAG, "Message: " + message);
        Log.d(TAG, "clickAction: " + clickAction);

        sendNotification(title, message, clickAction);
    }

}
项目:AppsTimeline    文件:MessageService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    Map<String, String> data = remoteMessage.getData();
    if (data.size() > 0) {
        Intent resultIntent = new Intent(this, MainActivity.class);
        PendingIntent resultPendingIntent = PendingIntent.getActivity(
                this,
                0,
                resultIntent,
                PendingIntent.FLAG_UPDATE_CURRENT
        );
        // 这个是应用在前台的时候出现的通知,应用在后台不会调用,这个并不能把应用拉起来的
        Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Notification n = new NotificationCompat.Builder(this, "channel.fcm")
                .setContentIntent(resultPendingIntent)
                .setContentTitle(data.get("title"))
                .setContentText(data.get("content"))
                .setSound(notificationSound)
                .setSmallIcon(R.drawable.ic_launcher)
                .build();
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if (notificationManager != null) notificationManager.notify(1, n);
    }
}
项目:1617PROJ1Bloeddonatie-app    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Log.d(TAG, "FROM:" + remoteMessage.getFrom());

    //Check if the message contains data
    if(remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data: " + remoteMessage.getData());
    }

    //Check if the message contains notification
    if(remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message body:" + remoteMessage.getNotification().getBody());
        sendNotification(remoteMessage.getNotification().getBody());
    }
}
项目:CSI-KJSCEOfficial    文件:CSINotificationService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Notification notification = parseNotification(remoteMessage);
    updateNotifDB(notification);

    intent = new Intent(this, NotificationActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent
            .getActivity(getBaseContext(),REQUEST_CODE, intent,PendingIntent.FLAG_ONE_SHOT);
    Uri soundUri = RingtoneManager
            .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this,"csi_channel");
    notifBuilder
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(notification.getTitle())
            .setAutoCancel(true)
            .setSound(soundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notifManager.notify(0,notifBuilder.build());
}
项目:CuYemek    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

    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)
                    .setSmallIcon(R.drawable.ic_action_notification)
                    .setContentTitle("Cü Yemek")
                    .setContentText("Yemek Listesi Yayımlandı.")
                    .setAutoCancel(true)

                    .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0,notificationBuilder.build());
    vib.vibrate(500);

}
项目:WaJeun    文件:PushService.java   
@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.

}
项目:androidadvanced    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // 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());

    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        sendNotification(remoteMessage.getNotification().getBody());
    }
}
项目:firebase-fcm-sample    文件:MyFirebaseMessagingService.java   
@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());
    }

    // 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.
}
项目:referendum_1o_android    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage != null && remoteMessage.getNotification() != null) {
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "referendum")
                .setLargeIcon(BitmapFactory.decodeResource(
                        getResources(), R.mipmap.ic_launcher))
                .setSmallIcon(R.drawable.ic_notification)
                .setContentTitle(StringsManager.getString("notification_title"))
                .setContentText(remoteMessage.getNotification().getBody());

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            notificationManager.notify(1, notificationBuilder.build());
        }
    }
}
项目:LNMOnlineAndroidSample    文件:MyFirebaseMessagingService.java   
@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());
        }
    }
}
项目:underlx    文件:FCMService.java   
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());
}
项目:FCM-toolbox    文件:Payload.java   
@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);
}
项目:app_secompufscar    文件:SECOMPFirebaseService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // TODO: 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.
    final String msg = remoteMessage.getNotification().getBody();

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        public void run() {
            Toast.makeText(getBaseContext(),"Acontecendo agora: "+msg,Toast.LENGTH_LONG).show();
        }
    });

}
项目:friendlychat-android    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // Handle data payload of FCM messages.
    Log.d(TAG, "FCM Message Id: " + remoteMessage.getMessageId());
    Log.d(TAG, "FCM Notification Message: " + remoteMessage.getNotification());
    Log.d(TAG, "FCM Data Message: " + remoteMessage.getData());
}
项目:justintrain-client-android    文件:AppFCMService.java   
private void showNotification(RemoteMessage remoteMessage) {
        String title = remoteMessage.getNotification().getTitle();
        String body  = remoteMessage.getNotification().getBody();

        Intent intent = new Intent(this, FavouriteJourneysActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_ONE_SHOT);
        if ((remoteMessage.getData().get("isDebugNotification") == null) ||
                remoteMessage.getData().get("isDebugNotification").equals("false") ||
                (remoteMessage.getData().get("isDebugNotification").equals("true") && BuildConfig.DEBUG)) {
//        Bitmap notifyImage     = BitmapFactory.decodeResource(getResources(), R.drawable.ic_notification2);
//        Uri    defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setDefaults(Notification.DEFAULT_SOUND)
                    .setSmallIcon(R.drawable.ic_notification2)
                    .setContentTitle(title)
                    .setContentText(body)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(body)
                            .setBigContentTitle(title)
                            .setSummaryText(body))
                    .setAutoCancel(true)
                    .setContentIntent(pendingIntent);

            if (remoteMessage.getData().get("isDiscountNotification").equals("true")) {
                ClickActionHelper.startActivity(remoteMessage.getData().get("on_notification_click_action"), null, this);
            }

            NotificationManager notificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(0, notificationBuilder.build());
        }
    }
项目:Pole-Beacon-Android-SDK    文件:MyFcmListenerService.java   
@Override
public void onMessageReceived(RemoteMessage message) {
    String from = message.getFrom();
    data = message.getData();
    if (PoleNotificationService.onMessageReceived(message, mContext)){
        generateNotification(data);
    }
}
项目:aftercare-app-android    文件:DCFirebaseMessagingService.java   
private void showNotification(RemoteMessage remoteMessage) {
    if (remoteMessage != null && remoteMessage.getNotification() != null) {
        String title = getString(R.string.txt_app_name);
        String message = "";

        Intent intent = new Intent(this, LaunchActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        if (remoteMessage.getNotification().getTitle() != null) {
            title = remoteMessage.getNotification().getTitle();
        }

        if (remoteMessage.getNotification().getBody() != null) {
            message = remoteMessage.getNotification().getBody();
        }


        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(title)
                .setContentText(message)
                .setSmallIcon(R.drawable.notification_icon)
                .setAutoCancel(true)
                .setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification))
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(DCSharedPreferences.getNotificationId(), notificationBuilder.build());
    }
}
项目:social-app-android    文件:MyFirebaseMessagingService.java   
private void handleNewPostCreatedAction(RemoteMessage remoteMessage) {
    String postAuthorId = remoteMessage.getData().get(AUTHOR_ID_KEY);
    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();

    //Send notification for each users except author of post.
    if (firebaseUser != null && !firebaseUser.getUid().equals(postAuthorId)) {
        PostManager.getInstance(this.getApplicationContext()).incrementNewPostsCounter();
    }
}
项目:quake-alert-android-app    文件:MyFirebaseMessagingService.java   
/**
 * 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());
    }

    // 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.
}
项目:Tech-Jalsa    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage == null)
        return;
    if (remoteMessage.getNotification() != null) {
        handleNotification(remoteMessage.getNotification().getBody());
    }
    if (remoteMessage.getData().size() > 0) {
        try {
            JSONObject json = new JSONObject(remoteMessage.getData().toString());
            handleDataMessage(json);
        } catch (Exception e) {
        }
    }
}
项目:Sem-Update    文件:MyFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.i(TAG, "DESDE: " + remoteMessage.getFrom());

    if(remoteMessage.getData().size() > 0){
        Log.i(TAG, "Data de mensaje: " + remoteMessage.getData());
    }

    if(remoteMessage.getNotification() != null){
        Log.i(TAG, "Notificacion.body: " + remoteMessage.getNotification().getBody());
        sendNotification(remoteMessage.getNotification().getBody());
    }
}
项目:Guanajoven    文件:FirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    //super.onMessageReceived(remoteMessage);
    Log.d("DEBUG", "Notificacion");
    Realm.init(this);
    realm = Realm.getDefaultInstance();
    showNotification(remoteMessage.getData().get("title"), remoteMessage.getData().get("body"), remoteMessage.getData().get("tag"));
}
项目:gdgApp    文件:MessagingService.java   
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
    //We will not send any payload to this device so no need to check this.

    Log.d(getClass().getSimpleName(),"Message Received from server while in foreground");

    //fixme : Make this logic backend for better results

    FirebaseDatabase.getInstance().getReference()
            .child("root")
            .child("notifications")
            .child("author")
            .addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    String email = dataSnapshot.getValue(String.class);
                    //noinspection ConstantConditions
                    if(Objects.equals(email, FirebaseAuth.getInstance().getCurrentUser().getEmail())){
                        Log.i("MessagingService","The sender of notification is the current user... Skip the next steps");
                        notifyMessageSent();
                    }
                    else
                        handleMessage(remoteMessage);
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
}
项目:android-things-blinking-led    文件:IoTMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("lightsOn",
                    "true".equals(remoteMessage.getData().get("lightsOn")));
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
}
项目:cordova-plugin-firebase-sdk    文件:MessagingService.java   
/**
 * 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);
    }
}
项目:cleanhood    文件:PushMessagingService.java   
/**
 * 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());
        sendNotification(remoteMessage.getNotification());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        sendNotification(remoteMessage.getNotification());
    }



    // 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.
}
项目:blockvote    文件:BlockvoteFirebaseMessagingService.java   
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    String from = remoteMessage.getFrom();
    switch (from) {
        case "/topics/v1":
        case "/topics/debug":
            Map<String, String> data = remoteMessage.getData();
            process(data);
            break;
    }
}
项目:Crypto-Assistant    文件:FbMessagingService.java   
/**
 * 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
        sendNotification(remoteMessage);
    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Logger.d("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) {
        Logger.d("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.
}
项目:Crypto-Assistant    文件:FbMessagingService.java   
/**
     * Create and show a simple notification containing the received FCM message.
     *
     */
    private void sendNotification(RemoteMessage remoteMessage) {
        //if this driver has an order still pending delivery, don't show notifs
        Intent intent = new Intent(this, MainActivity
                .class);
        Logger.d("message received");
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("message",remoteMessage.getData().get("orderId"));
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_CANCEL_CURRENT);
//                PendingIntent.FLAG_UPDATE_CURRENT);
//                PendingIntent.FLAG_ONE_SHOT);
        Uri path = Uri.parse("android.resource://ondemandmbile.crypto_assistant/raw/alert");
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher_round)
                .setContentTitle(remoteMessage.getData().get("title"))
                .setContentText(remoteMessage.getData().get("body"))
                .setAutoCancel(true)
                .setSound(path)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

    }