|
|
@@ -18,12 +18,15 @@ import android.util.Log;
|
|
|
import com.google.firebase.messaging.FirebaseMessagingService;
|
|
|
import com.google.firebase.messaging.RemoteMessage;
|
|
|
import com.google.gson.Gson;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import kr.co.zumo.app.R;
|
|
|
import kr.co.zumo.app.lifeplus.activity.MainActivity;
|
|
|
+import kr.co.zumo.app.lifeplus.bean.PushBean;
|
|
|
import kr.co.zumo.app.lifeplus.helper.FirebaseHelper;
|
|
|
+import kr.co.zumo.app.lifeplus.supervisor.PushMessageManager;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -58,9 +61,6 @@ public class FirebasePushService extends FirebaseMessagingService {
|
|
|
// 메시지 수신
|
|
|
@Override
|
|
|
public void onMessageReceived(RemoteMessage remoteMessage) {
|
|
|
- Log.i("APP# FirebasePushService | onMessageReceived", "|" + "onMessageReceived");
|
|
|
-
|
|
|
- // TODO(developer): Handle FCM messages here.
|
|
|
// Not getting messages here? See why this may be: https://goo.gl/39bRNJ
|
|
|
Log.d("APP# FirebasePushService | onMessageReceived", "|" + "From: " + remoteMessage.getFrom());
|
|
|
|
|
|
@@ -68,22 +68,16 @@ public class FirebasePushService extends FirebaseMessagingService {
|
|
|
if (remoteMessage.getData().size() > 0) {
|
|
|
Log.d("APP# FirebasePushService | onMessageReceived", "|" + "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();
|
|
|
- }
|
|
|
-
|
|
|
Map<String, String> data = remoteMessage.getData();
|
|
|
- String title = data.get("title");
|
|
|
- String message = data.get("content");
|
|
|
|
|
|
- Log.d("APP# FirebasePushService | onMessageReceived", "|" + new Gson().toJson(data));
|
|
|
+ Gson gson = new Gson();
|
|
|
+ JsonElement jsonElement = gson.toJsonTree(data);
|
|
|
+ PushBean bean = gson.fromJson(jsonElement, PushBean.class);
|
|
|
+ Log.d("APP# FirebasePushService | onMessageReceived", "|" + bean.toJson());
|
|
|
+
|
|
|
+ PushMessageManager.savePushMessages(new PushMessageManager(PushMessageManager.getPushMessages()).addPushBean(bean));
|
|
|
|
|
|
- sendNotification(title, message);
|
|
|
+ sendNotification(bean.getTitle(), bean.getContents());
|
|
|
}
|
|
|
|
|
|
// Check if message contains a notification payload.
|
|
|
@@ -91,13 +85,11 @@ public class FirebasePushService extends FirebaseMessagingService {
|
|
|
|
|
|
String title = remoteMessage.getNotification().getTitle();
|
|
|
String message = remoteMessage.getNotification().getBody();
|
|
|
- Log.d("APP# FirebasePushService | onMessageReceived", "| getNotice" + " title: " + title + ", message: " + message);
|
|
|
+ Log.d("APP# FirebasePushService | onMessageReceived", "| notification" + " title: " + title + ", message: " + message);
|
|
|
|
|
|
- sendNotification(title, message);
|
|
|
+// sendNotification(title, message);
|
|
|
}
|
|
|
|
|
|
- // 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.
|
|
|
}
|
|
|
|
|
|
// /**
|
|
|
@@ -111,7 +103,7 @@ public class FirebasePushService extends FirebaseMessagingService {
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
|
|
|
PendingIntent.FLAG_ONE_SHOT);
|
|
|
|
|
|
- String channelId = "id";
|
|
|
+ String channelId = "lifeplus_channel_id";
|
|
|
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
|
NotificationCompat.Builder notificationBuilder =
|
|
|
new NotificationCompat.Builder(this, channelId)
|