AutorÃa | Ultima modificación | Ver Log |
package com.cesams.twogetskills.service;import android.accounts.Account;import android.content.Intent;import android.util.Log;import com.cesams.twogetskills.Constants;import com.cesams.twogetskills.library.Functions;import com.google.firebase.messaging.FirebaseMessagingService;import com.google.firebase.messaging.RemoteMessage;import java.util.Map;public class FcmMessagingService extends FirebaseMessagingService {private static final String TAG = "C2GS - FcmMessageServ";private Account mConnectedAccount;@Overridepublic void onCreate() {super.onCreate();}public void onMessageReceived(RemoteMessage remoteMessage) {Log.d("FcmMessagingService", "onMessageReceived");if (remoteMessage.getData().size() > 0) {Log.d(TAG, "Message data payload: " + remoteMessage.getData());if(remoteMessage.getData().containsKey("command")) {String command = remoteMessage.getData().get("command").trim();Intent intent = new Intent(Constants.BROADCAST_TYPE_COMMAND);intent.putExtra("command", command);this.sendBroadcast(intent);}}if (remoteMessage.getNotification() != null) {String title = remoteMessage.getNotification().getTitle();String body = remoteMessage.getNotification().getBody();String command = "";int new_capsules = 0;if (remoteMessage.getData().size() > 0) {Log.d(TAG, "Message data payload: " + remoteMessage.getData());if(remoteMessage.getData().containsKey("command")) {command = remoteMessage.getData().get("command").trim();}if(remoteMessage.getData().containsKey("new_capsules")) {new_capsules = Functions.Numero2Int(remoteMessage.getData().get("new_capsules"));}}Log.d(TAG, "title = " + title);Log.d(TAG, "body = " + body);Log.d(TAG, "command = " + command);Log.d(TAG, "new_capsules = " + new_capsules);Intent intent = new Intent(Constants.BROADCAST_TYPE_NOTIFICATION);intent.putExtra("title", title);intent.putExtra("body", body);intent.putExtra("command", command);intent.putExtra("new_capsules", new_capsules);this.sendBroadcast(intent);}}public void onNewToken(String fcm_token){Log.d("FcmMessagingService", "onNewToken token = " + fcm_token);Intent intent = new Intent(Constants.BROADCAST_TYPE_TOKEN);intent.putExtra("token", Functions.trimNull(fcm_token));this.sendBroadcast(intent);}}