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


Java RemoteMessage.getData方法代碼示例

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


在下文中一共展示了RemoteMessage.getData方法的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: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Map<String, String> map = remoteMessage.getData();
    String notificationSrc = map.get("source");
    if (notificationSrc != null && notificationSrc.equals("community")) {
        LiNotificationPayload notificationPayload= new LiNotificationPayload();
        notificationPayload.setFromId(map.get("fromId"));
        notificationPayload.setFromName(map.get("fromName"));
        notificationPayload.setType(map.get("type"));
        notificationPayload.setMessage(map.get("message"));
        showCommunityNotification(this, notificationPayload);
    }
    else {
        //TODO this is the space where the developer will have his other notification layout setup
    }
}
 
開發者ID:lithiumtech,項目名稱:li-android-sdk-example,代碼行數:17,代碼來源:RefAppNotificationService.java

示例5: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
	Utils.d("Message From: " + remoteMessage.getFrom());
	Utils.d("Message From: " + remoteMessage.toString());

	// Check if message contains a data payload.
	if (remoteMessage.getData().size() > 0) {
		Map<String, String> data = remoteMessage.getData();

		Utils.d("Message data payload: " + data.toString());

		KeyValueStorage.set_context(this);
		handleData(data);
	}

	// Check if message contains a notification payload.
	if (remoteMessage.getNotification() != null) {
		Utils.d(
		"Notification Body: " + remoteMessage.getNotification().getBody());

		sendNotification(remoteMessage.getNotification().getBody(), this);
	}
}
 
開發者ID:FrogSquare,項目名稱:GodotFireBase,代碼行數:24,代碼來源:MessagingService.java

示例6: onMessageReceived

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

}
 
開發者ID:othreecodes,項目名稱:WaJeun,代碼行數:27,代碼來源:PushService.java

示例7: handleDisturbanceMessage

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

示例8: with

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

示例9: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:jsayol,項目名稱:cordova-plugin-firebase-sdk,代碼行數:41,代碼來源:MessagingService.java

示例10: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    HashMap<String, String> data = new HashMap<>(remoteMessage.getData());
    String model = data.get("model");

    switch (model) {
        case "project.teams":
            processProjectTeams(data);
            break;
    }
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:13,代碼來源:OdooWorkFCMService.java

示例11: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
/**
 * 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(this, getBundle(messageMap));
    }
    Log.i("Received: " + messageMap.toString());
  } catch (Throwable t) {
    Util.handleException(t);
  }
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:19,代碼來源:LeanplumPushFirebaseMessagingService.java

示例12: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    if (remoteMessage.getNotification() != null && remoteMessage.getData() != null && remoteMessage.getData().size() >= 1) {
        String title = remoteMessage.getNotification().getTitle();
        String message = remoteMessage.getNotification().getBody();
        String url = remoteMessage.getData().get("url");
        if(title!=null && title.length()>0 && message!=null && message.length()>0 && url!=null && url.length()>0)
        showNotificationWithUrl(this, title, message, url);
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:11,代碼來源:PushMessagesReceiver.java

示例13: onMessageReceived

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

示例14: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Map<String, String> map = remoteMessage.getData();
    String notificationSrc = map.get("source");
    if (notificationSrc != null && notificationSrc.equals("community")) {
        LiNotificationPayload notificationPayload= new LiNotificationPayload();
        notificationPayload.setFromId(map.get("fromId"));
        notificationPayload.setFromName(map.get("fromName"));
        notificationPayload.setType(map.get("type"));
        notificationPayload.setMessage(map.get("message"));
        showCommunityNotification(this, notificationPayload);
    }
}
 
開發者ID:lithiumtech,項目名稱:li-android-sdk-core,代碼行數:14,代碼來源:LiFirebaseMessagingService.java

示例15: handlePushNotification

import com.google.firebase.messaging.RemoteMessage; //導入方法依賴的package包/類
private void handlePushNotification(RemoteMessage message) {
    Map<String, String> data = message.getData();

    String msg = data.get("message");
    String title = data.get("title");

    createNotification(msg, title);
    sendMessage("update");
}
 
開發者ID:humaniq,項目名稱:humaniq-android,代碼行數:10,代碼來源:FcmListenerService.java


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