當前位置: 首頁>>代碼示例>>Java>>正文


Java RemoteMessage類代碼示例

本文整理匯總了Java中com.google.firebase.messaging.RemoteMessage的典型用法代碼示例。如果您正苦於以下問題:Java RemoteMessage類的具體用法?Java RemoteMessage怎麽用?Java RemoteMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RemoteMessage類屬於com.google.firebase.messaging包,在下文中一共展示了RemoteMessage類的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);
    }
}
 
開發者ID:humaniq,項目名稱:humaniq-android,代碼行數:25,代碼來源:FcmListenerService.java

示例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);
    }
}
 
開發者ID:nen155,項目名稱:TFG-SmartU-La-red-social,代碼行數:23,代碼來源:MyFirebaseMessagingService.java

示例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);
    }
}
 
開發者ID:emartech,項目名稱:android-mobile-engage-sdk,代碼行數:24,代碼來源:MobileEngageMessagingService.java

示例4: parseCommentOrLike

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
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));
}
 
開發者ID:rozdoum,項目名稱:social-app-android,代碼行數:17,代碼來源:MyFirebaseMessagingService.java

示例5: displayNotification

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
/**
 * 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());
}
 
開發者ID:nen155,項目名稱:TFG-SmartU-La-red-social,代碼行數:27,代碼來源:MyFirebaseMessagingService.java

示例6: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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());
    }
}
 
開發者ID:UTN-FRBA-Mobile,項目名稱:Clases-2017c1,代碼行數:17,代碼來源:MyFirebaseMessagingService.java

示例7: parseColor

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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;
}
 
開發者ID:franmontiel,項目名稱:FcmNotificationHandler,代碼行數:19,代碼來源:RemoteMessageToNotificationMapper.java

示例8: handleRemoteMessage

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
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;
    }
}
 
開發者ID:rozdoum,項目名稱:social-app-android,代碼行數:17,代碼來源:MyFirebaseMessagingService.java

示例9: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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());
}
 
開發者ID:prabhavgupta,項目名稱:BookED,代碼行數:17,代碼來源:MyFirebaseMessagingService.java

示例10: handleMessage

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
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());
        }


    }
 
開發者ID:coder3101,項目名稱:gdgApp,代碼行數:25,代碼來源:MessagingService.java

示例11: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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());
        }
    }
}
 
開發者ID:ThomasDelaney,項目名稱:TapIn,代碼行數:17,代碼來源:MyFirebaseMessagingService.java

示例12: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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);
    }

}
 
開發者ID:gothalo,項目名稱:Android-2017,代碼行數:22,代碼來源:FirebaseMessangingService.java

示例13: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:zhaobao,項目名稱:AppsTimeline,代碼行數:26,代碼來源:MessageService.java

示例14: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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());
	}
}
 
開發者ID:team-htbr,項目名稱:1617PROJ1Bloeddonatie-app,代碼行數:17,代碼來源:MyFirebaseMessagingService.java

示例15: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入依賴的package包/類
@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());
}
 
開發者ID:CSI-KJSCE,項目名稱:CSI-KJSCEOfficial,代碼行數:24,代碼來源:CSINotificationService.java


注:本文中的com.google.firebase.messaging.RemoteMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。