diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index b1c9205..209992c 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -16,6 +16,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
_updateAppBadge(int count) async {
+ try {
+ await AppBadgePlus.updateBadge(count);
+ if (Get.isLogEnable) {
+ Get.log('✅ [ConversationController] 应用角标已更新: $count');
+ }
+ } catch (e) {
+ if (Get.isLogEnable) {
+ Get.log('⚠️ [ConversationController] 更新应用角标失败: $e');
+ }
+ }
+ }
+
/// 检查 IM 登录状态并加载会话列表
Future _checkAndLoadConversations() async {
// 如果已登录,直接加载
@@ -481,6 +500,8 @@ class ConversationController extends GetxController {
total += unreadCount;
}
totalUnreadCount.value = total;
+ // 更新应用角标
+ await _updateAppBadge(total);
if (Get.isLogEnable) {
Get.log('✅ [ConversationController] 总未读数已更新: $total');
}
@@ -489,6 +510,8 @@ class ConversationController extends GetxController {
Get.log('⚠️ [ConversationController] 更新总未读数失败: $e');
}
totalUnreadCount.value = 0;
+ // 更新应用角标为 0
+ await _updateAppBadge(0);
}
}
diff --git a/lib/im/im_manager.dart b/lib/im/im_manager.dart
index a8ff812..2f409fc 100644
--- a/lib/im/im_manager.dart
+++ b/lib/im/im_manager.dart
@@ -214,7 +214,11 @@ class IMManager {
if (message.direction == MessageDirection.RECEIVE && message.onlineState) {
_parseUserInfoFromMessageExt(message);
// 检查发送者是否是当前正在聊天的用户,如果不是则显示弹框
- _checkAndShowNotificationDialog(message);
+ // 只有在 APP 处于前台时才显示弹框
+ final lifecycleState = WidgetsBinding.instance.lifecycleState;
+ if (lifecycleState == AppLifecycleState.resumed) {
+ _checkAndShowNotificationDialog(message);
+ }
}
}
// 收到新消息时,更新会话列表