App crashes on Android 9.0 Pie when tapping on the ObjectBox Data Browser Notification and then the Browser doesn't load
java.lang.RuntimeException: Unable to start service io.objectbox.android.AndroidObjectBrowserService@56a7c2e with Intent { cmp=com.package/io.objectbox.android.AndroidObjectBrowserService (has extras) }: java.lang.SecurityException: Permission Denial: startForeground from pid=31182, uid=10273 requires android.permission.FOREGROUND_SERVICE
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3686)
at android.app.ActivityThread.access$1600(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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:858)
Caused by: java.lang.SecurityException: Permission Denial: startForeground from pid=31182, uid=10273 requires android.permission.FOREGROUND_SERVICE
at android.os.Parcel.createException(Parcel.java:1942)
at android.os.Parcel.readException(Parcel.java:1910)
at android.os.Parcel.readException(Parcel.java:1860)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:5198)
at android.app.Service.startForeground(Service.java:695)
at io.objectbox.android.AndroidObjectBrowserService.onStartCommand(AndroidObjectBrowserService.java:79)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3667)
at android.app.ActivityThread.access$1600(ActivityThread.java:199)聽
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)聽
at android.os.Handler.dispatchMessage(Handler.java:106)聽
at android.os.Looper.loop(Looper.java:193)聽
at android.app.ActivityThread.main(ActivityThread.java:6669)聽
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:858)聽
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.enforcePermission(ActivityManagerService.java:9186)
at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:1189)
at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:870)
at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:20434)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:976)
Solved by adding the following permission in AndroidManifest.xml
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
Thanks for reporting. I assume your app is targeting API 28?
Apps that target Android 9 or higher and use foreground services must request the FOREGROUND_SERVICE permission. This is a normal permission, so the system automatically grants it to the requesting app.
Source: https://developer.android.com/about/versions/pie/android-9.0-changes-28
-ut
Yes my app is targeting API 28. Thanks.
Decided to add both the INTERNET and FOREGROUND_SERVICE permission to the manifest of the objectbox-android-objectbrowser artifact. The start() method continues to immediately check for required permissions in case users exclude the merged permissions.
If the data browser is set up as recommended, the permission tags will only be merged for debug builds (because the objectbox-android artifact used for release builds does not have them).
This is simpler than asking the user to create a debug build manifest.
data-browser-api-28 branch).-ut
Thanks a lot for your response. Been waiting for ObjectBox's Sync feature eagerly <3
We just released version 2.2.0 with a fix. Please let us know if it is working for you. Thanks!
Tasks completed, so closing this as well. Please re-open if this continues to be an issue. -ut
Most helpful comment
Decided to add both the INTERNET and FOREGROUND_SERVICE permission to the manifest of the
objectbox-android-objectbrowserartifact. Thestart()method continues to immediately check for required permissions in case users exclude the merged permissions.If the data browser is set up as recommended, the permission tags will only be merged for debug builds (because the
objectbox-androidartifact used for release builds does not have them).This is simpler than asking the user to create a debug build manifest.
data-browser-api-28branch).-ut