diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt index 26e9cf2b9..5c6415e49 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/BleMediaService.kt @@ -413,7 +413,7 @@ private var companionManager: BleCompanionManager? = null // 设置服务状态 isRunning.set(true) startForeground(NOTIFICATION_ID, createNotification()) - // 初始化BLE伴侣设备管理器 - 使用单例模式获取实例 + // 初始化BLE伴侣设备管理器 - 使用单例模式获取实例 companionManager = BleCompanionManager.getInstance(this) // 初始化蓝牙监听器 initializeBluetoothListener() @@ -850,12 +850,20 @@ private var companionManager: BleCompanionManager? = null // Android 8.0+ 需要创建通知渠道 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val channel = NotificationChannel( - CHANNEL_ID, - "语音助手代理服务", - NotificationManager.IMPORTANCE_LOW - ) - manager.createNotificationChannel(channel) + val existingChannel = manager.getNotificationChannel(CHANNEL_ID) + if (existingChannel == null) { + val channel = NotificationChannel( + CHANNEL_ID, + "Voice assistant agent", + NotificationManager.IMPORTANCE_LOW + ) + channel.description = "Voice assistant agent" + channel.setShowBadge(false) + channel.enableLights(false) + channel.enableVibration(false) + channel.lockscreenVisibility = Notification.VISIBILITY_PRIVATE + manager.createNotificationChannel(channel) + } } // 点击通知打开主界面 @@ -873,15 +881,22 @@ private var companionManager: BleCompanionManager? = null null } + val appIconResId = applicationInfo.icon.takeIf { it != 0 } ?: android.R.drawable.ic_dialog_info + // 构建通知 val builder = NotificationCompat.Builder(this, CHANNEL_ID) .setContentTitle("Voitrans") - .setContentText("语音助手代理服务运行中") - .setSmallIcon(android.R.drawable.ic_dialog_info) + .setContentText("Voice assistant agent is running") + .setSmallIcon(appIconResId) + .setOngoing(true) + .setOnlyAlertOnce(true) + .setCategory(NotificationCompat.CATEGORY_SERVICE) + .setPriority(NotificationCompat.PRIORITY_LOW) + .setShowWhen(false) // 设置点击意图 pendingIntent?.let { builder.setContentIntent(it) } return builder.build() } -} \ No newline at end of file +}