Skip to content

Commit 2142a66

Browse files
authored
Merge pull request #169 from SXiaoXu/update_fcm
update fcm service
2 parents 25e85d4 + 6017dc8 commit 2142a66

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

android-sdk/leancloud-fcm/src/main/java/cn/leancloud/AVFirebaseMessagingService.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,27 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
3535
return;
3636
}
3737
LOGGER.d("received message from: " + remoteMessage.getFrom() + ", payload: " + data.toString());
38+
39+
if (remoteMessage.getNotification() == null) {
40+
return;
41+
}
42+
String title = remoteMessage.getNotification().getTitle();
43+
String alert = remoteMessage.getNotification().getBody();
44+
3845
try {
3946
JSONObject jsonObject = JSON.parseObject(data.get("payload"));
4047
if (null != jsonObject) {
4148
String channel = jsonObject.getString("_channel");
4249
String action = jsonObject.getString("action");
4350

51+
if (!StringUtil.isEmpty(title)) {
52+
jsonObject.put("title", title);
53+
}
54+
if (!StringUtil.isEmpty(alert)) {
55+
jsonObject.put("alert", alert);
56+
}
4457
AndroidNotificationManager androidNotificationManager = AndroidNotificationManager.getInstance();
45-
androidNotificationManager.processGcmMessage(channel, action, jsonObject.toJSONString());
58+
androidNotificationManager.processFcmMessage(channel, action, jsonObject.toJSONString());
4659
}
4760
} catch (Exception ex) {
4861
LOGGER.e("failed to parse push data.", ex);

android-sdk/realtime-android/src/main/java/cn/leancloud/push/AndroidNotificationManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,17 @@ public void processMixNotification(String message, String defaultAction) {
233233
}
234234

235235
/**
236-
* 处理 GCM 的透传消息
236+
* 处理 FCM 的透传消息
237237
* @param channel
238238
* @param action
239239
* @param message
240240
*/
241-
public void processGcmMessage(String channel, String action, String message) {
242-
if (channel == null || !containsDefaultPushCallback(channel)) {
243-
channel = AVOSCloud.getApplicationId();
241+
public void processFcmMessage(String channel, String action, String message) {
242+
if (!StringUtil.isEmpty(message)) {
243+
if (channel == null || !containsDefaultPushCallback(channel)) {
244+
channel = AVOSCloud.getApplicationId();
245+
}
246+
244247
if (action != null) {
245248
sendBroadcast(channel, message, action);
246249
} else {

0 commit comments

Comments
 (0)