Leakcanary: startForeground requires android.permission.FOREGROUND_SERVICE

Created on 7 Aug 2018  路  1Comment  路  Source: square/leakcanary

I'm using Android Pie (9). Leaks are not detected and leaks launcher icon is also not listed in apps listing.
Got this stacktrace from logcat

java.lang.RuntimeException: Unable to create service com.squareup.leakcanary.internal.HeapAnalyzerService: java.lang.SecurityException: Permission Denial: startForeground from requires android.permission.FOREGROUND_SERVICE

This is due to the change in Android Pie.
Refer https://developer.android.com/guide/components/services#Foreground

Note: Apps that target Android 9.0 (API level 28) 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.
If an app that targets API level 28 or higher attempts to create a foreground service without requesting FOREGROUND_SERVICE, the system throws a SecurityException.

Solution: Need to add FOREGROUND_SERVICE permission in manifest.

Most helpful comment

Thanks for the report. Fixed in #1076

>All comments

Thanks for the report. Fixed in #1076

Was this page helpful?
0 / 5 - 0 ratings