From b4e2b213064e9e6eeeda2ac3cfea80b43232dbe2 Mon Sep 17 00:00:00 2001 From: jjangddu Date: Wed, 6 May 2026 12:30:54 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B0=B0=ED=84=B0=EB=A6=AC=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94=20=EC=A0=9C=EC=99=B8=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?(Doze=20=EB=A9=B4=EC=A0=9C,=20=EC=82=BC=EC=84=B1=20=EB=8C=80?= =?UTF-8?q?=EC=9D=91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BLE 연결 시 REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 다이얼로그 표시 - 이미 제외 상태면 스킵 - Manifest에 REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 권한 추가 Co-Authored-By: Claude Opus 4.6 (1M context) --- app/src/main/AndroidManifest.xml | 1 + .../services/BleForegroundService.kt | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1fc60b9..6657d19 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,6 +31,7 @@ + diff --git a/app/src/main/java/com/example/medilightv2android/services/BleForegroundService.kt b/app/src/main/java/com/example/medilightv2android/services/BleForegroundService.kt index 73ab087..aead786 100644 --- a/app/src/main/java/com/example/medilightv2android/services/BleForegroundService.kt +++ b/app/src/main/java/com/example/medilightv2android/services/BleForegroundService.kt @@ -29,6 +29,9 @@ class BleForegroundService : Service() { const val ACTION_STOP = "com.example.medilightv2android.BLE_STOP" fun start(context: Context) { + // 배터리 최적화 제외 요청 (Doze 면제) + requestBatteryOptimizationExemption(context) + val intent = Intent(context, BleForegroundService::class.java).apply { action = ACTION_START } @@ -39,6 +42,22 @@ class BleForegroundService : Service() { } } + @android.annotation.SuppressLint("BatteryLife") + private fun requestBatteryOptimizationExemption(context: Context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager + if (!pm.isIgnoringBatteryOptimizations(context.packageName)) { + try { + val intent = Intent(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply { + data = android.net.Uri.parse("package:${context.packageName}") + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + context.startActivity(intent) + } catch (_: Exception) {} + } + } + } + fun stop(context: Context) { val intent = Intent(context, BleForegroundService::class.java).apply { action = ACTION_STOP