All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yy.httpproxy.thirdparty.MyFirebaseMessagingService Maven / Gradle / Ivy

There is a newer version: 1.1.28
Show newest version
package com.yy.httpproxy.thirdparty;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.yy.httpproxy.service.ForegroundService;
import com.yy.httpproxy.service.PushedNotification;
import com.yy.httpproxy.util.Log;

import org.json.JSONObject;

/**
 * Created by xuduo on 08/03/2018.
 */

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static final String TAG = MyFirebaseMessagingService.class.getName();

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        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.getData());

            try {

                JSONObject obj = new JSONObject(remoteMessage.getNotification().getBody());
                PushedNotification pushedNotification = new PushedNotification(obj.getString("id"), obj);

                if (ForegroundService.instance != null) {
                    ForegroundService.instance.onNotification(pushedNotification);
                }

                Log.d("Message ", obj.getString("id"));

            } catch (Throwable t) {
                Log.e("My App", "Could not parse malformed JSON: \"" + remoteMessage.getNotification().getBody() + "\"");
            }

        }

    }



}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy