Caused by: java.lang.SecurityException: Permission Denial: startForeground from pid=6412, uid=10599 requires android.permission.FOREGROUND_SERVICE
2019-04-06 23:57:25.081 6412-6419/? E/eusingvibratio: Failed to send DDMS packet REAQ to debugger (-1 of 20): Broken pipe
2019-04-06 23:57:34.693 6412-6412/ddolcatmaster.bodymassageusingvibration E/AndroidRuntime: FATAL EXCEPTION: main
Process: ddolcatmaster.bodymassageusingvibration, PID: 6412
java.lang.RuntimeException: Unable to create service ddolcatmaster.bodymassageusingvibration.BatteryNotificationService: java.lang.SecurityException: Permission Denial: startForeground from pid=6412, uid=10599 requires android.permission.FOREGROUND_SERVICE
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3587)
at android.app.ActivityThread.access$1300(ActivityThread.java:204)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1674)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
Caused by: java.lang.SecurityException: Permission Denial: startForeground from pid=6412, uid=10599 requires android.permission.FOREGROUND_SERVICE
at android.os.Parcel.createException(Parcel.java:1950)
at android.os.Parcel.readException(Parcel.java:1918)
at android.os.Parcel.readException(Parcel.java:1868)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:5080)
at android.app.Service.startForeground(Service.java:695)
at ddolcatmaster.bodymassageusingvibration.BatteryNotificationService.onCreate(BatteryNotificationService.java:34)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3575)
at android.app.ActivityThread.access$1300(ActivityThread.java:204)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1674)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.enforcePermission(ActivityManagerService.java:9720)
at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:1200)
at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:881)
at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:21236)
at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:10767)
2019-04-06 23:57:34.770 6412-6412/ddolcatmaster.bodymassageusingvibration E/UncaughtException: java.lang.RuntimeException: Unable to create service ddolcatmaster.bodymassageusingvibration.BatteryNotificationService: java.lang.SecurityException: Permission Denial: startForeground from pid=6412, uid=10599 requires android.permission.FOREGROUND_SERVICE
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3587)
at android.app.ActivityThread.access$1300(ActivityThread.java:204)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1674)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
Caused by: java.lang.SecurityException: Permission Denial: startForeground from pid=6412, uid=10599 requires android.permission.FOREGROUND_SERVICE
at android.os.Parcel.createException(Parcel.java:1950)
at android.os.Parcel.readException(Parcel.java:1918)
at android.os.Parcel.readException(Parcel.java:1868)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:5080)
at android.app.Service.startForeground(Service.java:695)
at ddolcatmaster.bodymassageusingvibration.BatteryNotificationService.onCreate(BatteryNotificationService.java:34)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3575)
at android.app.ActivityThread.access$1300(ActivityThread.java:204)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1674)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.enforcePermission(ActivityManagerService.java:9720)
at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:1200)
at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:881)
at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:21236)
at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:10767)
2019-04-06 23:57:35.742 6412-6665/ddolcatmaster.bodymassageusingvibration E/FirebaseCrash: Unable to parse Json response string to get message: No value for crashes
2019-04-06 23:57:49.704 6704-6704/ddolcatmaster.bodymassageusingvibration E/ActivityThread: Service ddolcatmaster.bodymassageusingvibration.BatteryNotificationService has leaked IntentReceiver ddolcatmaster.bodymassageusingvibration.BatteryNotificationService$1@2d0a6b2 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Service ddolcatmaster.bodymassageusingvibration.BatteryNotificationService has leaked IntentReceiver ddolcatmaster.bodymassageusingvibration.BatteryNotificationService$1@2d0a6b2 that was originally registered here. Are you missing a call to unregisterReceiver()?
at android.app.LoadedApk$ReceiverDispatcher.(LoadedApk.java:1433)
at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1214)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1501)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1474)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1462)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:623)
at ddolcatmaster.bodymassageusingvibration.BatteryNotificationService.onStartCommand(BatteryNotificationService.java:69)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3720)
at android.app.ActivityThread.access$1600(ActivityThread.java:204)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1689)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
2019-04-07 00:07:42.188 8175-8175/ddolcatmaster.bodymassageusingvibration E/AndroidRuntime: FATAL EXCEPTION: main
Process: ddolcatmaster.bodymassageusingvibration, PID: 8175
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 backgroundColor=0x00000000 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1745)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
2019-04-07 00:07:42.258 8175-8175/ddolcatmaster.bodymassageusingvibration E/UncaughtException: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 backgroundColor=0x00000000 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1745)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:860)
2019-04-07 00:07:43.272 8175-8348/ddolcatmaster.bodymassageusingvibration E/FirebaseCrash: Unable to parse Json response string to get message: No value for crashes
2019-04-07 00:07:43.595 8175-8348/ddolcatmaster.bodymassageusingvibration E/FirebaseCrash: Unable to parse Json response string to get message: No value for crashes
targetSdkVersion을 28로 올렸다.
그리하였더니 권한 오류가 발생하였다.
포그라운드 서비스를 이용하려면 FOREGROUND_SERVICE 권한을 요청해야한다.
동작 변경사항: API 레벨 28+를 대상으로 하는 앱
Android 9 이상을 대상으로 하고 포그라운드 서비스를 사용하는 앱은 FOREGROUND_SERVICE 권한을 요청해야 합니다. 이 권한은 정상 권한이므로, 시스템은 요청 앱에 자동으로 권한을 부여합니다.
Manifest 파일에 추가하면된다.
<uses-permission android:name=“android.permission.FOREGROUND_SERVICE” />