From b48b2ecc0882fb68ae0c6bd631bb5b913fe1428c Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 03 十二月 2025 17:38:40 +0800
Subject: [PATCH] 2025年12月03日17:37:56 集成小米商厂
---
app/src/main/java/com/hdl/photovoltaic/push/fcm/MyFirebaseMessagingService.java | 47 +++++++++++++++++++++++++++--------------------
1 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/push/fcm/MyFirebaseMessagingService.java b/app/src/main/java/com/hdl/photovoltaic/push/fcm/MyFirebaseMessagingService.java
index c1c45c4..492b4cf 100644
--- a/app/src/main/java/com/hdl/photovoltaic/push/fcm/MyFirebaseMessagingService.java
+++ b/app/src/main/java/com/hdl/photovoltaic/push/fcm/MyFirebaseMessagingService.java
@@ -26,6 +26,7 @@
import com.hdl.photovoltaic.push.PushMessageInfoBean;
import com.hdl.photovoltaic.ui.BPowerStationActivity;
import com.hdl.photovoltaic.ui.StartActivity;
+import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
import org.greenrobot.eventbus.EventBus;
@@ -37,6 +38,9 @@
import cn.jpush.android.api.NotificationMessage;
+/**
+ * 璋锋瓕鎺ㄩ�佹秷鎭帴鏀舵柟娉�
+ */
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCMService";
@@ -57,9 +61,6 @@
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "鍦ㄥ墠鍙拌繕鏄湪鍚�" + isAppInForeground(this));
Log.d(TAG, "鏉ヨ嚜RemoteMessage: " + JSON.toJSONString(remoteMessage));
- Log.d(TAG, "鏉ヨ嚜: " + remoteMessage.getFrom());
-
-
// // 鏁版嵁娑堟伅锛氫换浣曠姸鎬侀兘浼氭墽琛�
// if (!remoteMessage.getData().isEmpty()) {
// handleDataMessage(remoteMessage.getData()); // 鎬绘槸鎵ц
@@ -69,19 +70,24 @@
// if (remoteMessage.getNotification() != null) {
// handleNotification(remoteMessage.getNotification()); // 鍙湁鍓嶅彴鎵ц
// }
-
- if (isAppInForeground(this)) {
+ String title = "";//鎺ㄩ�佹爣棰�
+ String content = "";//鎺ㄩ�佸唴瀹�
+ if (remoteMessage.getNotification() != null) {
+ title = remoteMessage.getNotification().getTitle();
+ content = remoteMessage.getNotification().getBody();
+ }
+ //鍘熺敓鍦ㄥ墠鍙版垨鑰卽ni鍦ㄥ墠鍙�
+ if (isAppInForeground(this) || HDLUniMPSDKManager.getInstance().showUniMP()) {
// 妫�鏌ユ秷鎭槸鍚﹀寘鍚暟鎹礋杞�
if (!remoteMessage.getData().isEmpty()) {
- PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing("", "", JSON.toJSONString(remoteMessage.getData()));
+ PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing(title, content, JSON.toJSONString(remoteMessage.getData()));
HdlPushLogic.getInstance().PushPushCommonData(this, pushMessageInfoBean, false);
-// Log.d(TAG, "娑堟伅鏁版嵁: " + remoteMessage.getData());
-// handleDataMessage(remoteMessage.getData());
+// this.showCustomNotification(pushMessageInfoBean);
}
} else {
// 妫�鏌ユ秷鎭槸鍚﹀寘鍚�氱煡璐熻浇
if (!remoteMessage.getData().isEmpty()) {
- PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing("", "", JSON.toJSONString(remoteMessage.getData()));
+ PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing(title, content, JSON.toJSONString(remoteMessage.getData()));
this.showCustomNotification(pushMessageInfoBean);
}
}
@@ -102,38 +108,40 @@
createNotificationChannel(notificationManager);
}
+ // 鏋勫缓閫氱煡鍐呭
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "fcm_channel")
- .setSmallIcon(R.drawable.desktop_logo)
+ .setSmallIcon(R.drawable.notification_logo)
.setContentTitle(pushMessageInfoBean.getTitle())
.setContentText(pushMessageInfoBean.getContent())
.setAutoCancel(true)
.setWhen(System.currentTimeMillis());
- // 璁剧疆鐐瑰嚮鎰忓浘
- Intent intent = createNotificationIntent(pushMessageInfoBean.getExpandData());
+ // 璁剧疆鐐瑰嚮鎰忓浘,涓洪�氱煡娣诲姞鐐瑰嚮鍚庣殑璺宠浆鎰忓浘
+ Intent intent = createNotificationIntent(pushMessageInfoBean);
PendingIntent pendingIntent = PendingIntent.getActivity(
this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
builder.setContentIntent(pendingIntent);
- // 鏄剧ず閫氱煡
- notificationManager.notify((int) System.currentTimeMillis(), builder.build());
+ // 鍙戦�侀�氱煡,閫氱煡鏍忔樉绀洪�氱煡
+ int notificationId = (int) System.currentTimeMillis(); // 姣忎釜閫氱煡鐨勫敮涓�ID
+ notificationManager.notify(notificationId, builder.build());
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void createNotificationChannel(NotificationManager notificationManager) {
NotificationChannel channel = new NotificationChannel(
"fcm_channel",
- "FCM 娑堟伅",
+ "FCM Message",
NotificationManager.IMPORTANCE_HIGH
);
- channel.setDescription("Firebase Cloud Messaging 閫氱煡");
+ channel.setDescription("Firebase Cloud Messaging Notification");
notificationManager.createNotificationChannel(channel);
}
- private Intent createNotificationIntent(String data) {
+ private Intent createNotificationIntent(PushMessageInfoBean pushMessageInfoBean) {
Intent intent = new Intent(this, StartActivity.class);
intent.putExtra("from_fcm", true);
- intent.putExtra("pushData", data);
+ intent.putExtra("pushData", JSONObject.toJSONString(pushMessageInfoBean));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
@@ -145,8 +153,7 @@
if (TextUtils.isEmpty(token)) {
return;
}
- UserConfigManage.getInstance().setPushToken(token);
- UserConfigManage.getInstance().Save();
+
BaseEventBus bus = new BaseEventBus();
bus.setTopic(ConstantManage.refresh_push_token);
bus.setType(token);
--
Gitblit v1.8.0