|
|
@ -413,7 +413,7 @@ private var companionManager: BleCompanionManager? = null |
|
|
// 设置服务状态 |
|
|
// 设置服务状态 |
|
|
isRunning.set(true) |
|
|
isRunning.set(true) |
|
|
startForeground(NOTIFICATION_ID, createNotification()) |
|
|
startForeground(NOTIFICATION_ID, createNotification()) |
|
|
// 初始化BLE伴侣设备管理器 - 使用单例模式获取实例 |
|
|
// 初始化BLE伴侣设备管理器 - 使用单例模式获取实例 |
|
|
companionManager = BleCompanionManager.getInstance(this) |
|
|
companionManager = BleCompanionManager.getInstance(this) |
|
|
// 初始化蓝牙监听器 |
|
|
// 初始化蓝牙监听器 |
|
|
initializeBluetoothListener() |
|
|
initializeBluetoothListener() |
|
|
@ -850,12 +850,20 @@ private var companionManager: BleCompanionManager? = null |
|
|
|
|
|
|
|
|
// Android 8.0+ 需要创建通知渠道 |
|
|
// Android 8.0+ 需要创建通知渠道 |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
|
val channel = NotificationChannel( |
|
|
val existingChannel = manager.getNotificationChannel(CHANNEL_ID) |
|
|
CHANNEL_ID, |
|
|
if (existingChannel == null) { |
|
|
"语音助手代理服务", |
|
|
val channel = NotificationChannel( |
|
|
NotificationManager.IMPORTANCE_LOW |
|
|
CHANNEL_ID, |
|
|
) |
|
|
"Voice assistant agent", |
|
|
manager.createNotificationChannel(channel) |
|
|
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 |
|
|
null |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val appIconResId = applicationInfo.icon.takeIf { it != 0 } ?: android.R.drawable.ic_dialog_info |
|
|
|
|
|
|
|
|
// 构建通知 |
|
|
// 构建通知 |
|
|
val builder = NotificationCompat.Builder(this, CHANNEL_ID) |
|
|
val builder = NotificationCompat.Builder(this, CHANNEL_ID) |
|
|
.setContentTitle("Voitrans") |
|
|
.setContentTitle("Voitrans") |
|
|
.setContentText("语音助手代理服务运行中") |
|
|
.setContentText("Voice assistant agent is running") |
|
|
.setSmallIcon(android.R.drawable.ic_dialog_info) |
|
|
.setSmallIcon(appIconResId) |
|
|
|
|
|
.setOngoing(true) |
|
|
|
|
|
.setOnlyAlertOnce(true) |
|
|
|
|
|
.setCategory(NotificationCompat.CATEGORY_SERVICE) |
|
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_LOW) |
|
|
|
|
|
.setShowWhen(false) |
|
|
|
|
|
|
|
|
// 设置点击意图 |
|
|
// 设置点击意图 |
|
|
pendingIntent?.let { builder.setContentIntent(it) } |
|
|
pendingIntent?.let { builder.setContentIntent(it) } |
|
|
|
|
|
|
|
|
return builder.build() |
|
|
return builder.build() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|