Logcat
java.lang.SecurityException: Permission Denial: startForeground
Foreground Service를 시작할 때(startForeground) 발생하는 오류입니다.
🟡 오류 해결하기 🟡
우선, Manifest에 FOREGROUND_SERVICE 권한이 제대로 선언되어 있는지 확인합니다.
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
- 안드로이드 9 (API 28) 버전부터는 Foregroud Service를 시작할 때 Notification을 제공해야 합니다.
- 안드로이드 10 (API 29) 버전부터는 백그라운드에서 Foreground Service를 시작할 수 없습니다.
서비스에서 위치 정보를 사용한다면 위치 정보 관련 권한을 런타임 시 요청해야 합니다.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ActivityCompat.requestPermissions(
this,
arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.FOREGROUND_SERVICE),
REQUEST_CODE
)
}
'개발 과정 > 문제 해결' 카테고리의 다른 글
안드로이드 스튜디오 Git push 되돌리기 (잘못 push했을 때 해결 방법) (0) | 2024.12.30 |
---|---|
Compose Preview가 안 나올 때 해결 방법 (0) | 2024.11.19 |
BuildConfig import가 안 될 때 해결 방법 (0) | 2024.11.18 |
R이 import 되지 않을 때 해결 방법 (0) | 2024.11.17 |
java.lang.RuntimeException: Unable to instantiate activity 오류 해결 (0) | 2024.11.16 |