My app has <uses-permission android:name="android.permission.WAKE_LOCK" />
added to the AndroidManifest.xml
. However calls to acquire the lock PowerManager.PARTIAL_WAKE_LOCK
crash the app on Oreo devices.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.SecurityException: Neither user 10094 nor current process has android.permission.WAKE_LOCK.
permission. WAKE_LOCK permission in an <uses-permission> element of the application's manifest. Obtain a wake lock by calling PowerManager#newWakeLock(int, String) . Call acquire() to acquire the wake lock and force the device to stay on at the level that was requested when the wake lock was created.
A wake lock is a mechanism to indicate that your application needs to have the device stay on. Any application using a WakeLock must request the android. permission. WAKE_LOCK permission in an <uses-permission> element of the application's manifest.
Call Settings. System. canWrite() to see if you are eligible to write out settings. If canWrite() returns false , start up the ACTION_MANAGE_WRITE_SETTINGS activity so the user can agree there to allow your app to actually write to settings.
Your app is probably using a new version of ACRA library. In new the version they added <uses-permission android:name="android.permission.WAKE_LOCK" android:maxSdkVersion="25" />
to the lib AndroidManifest.xml
file. The android:maxSdkVersion="25"
is silently merged to main app AndroidManifest.xml
file, hence the app doesn't have WAKE_LOCK
permission on Oreo devices. The solution is add tools:node="replace"
to your uses-permission declaration.
For example <uses-permission android:name="android.permission.WAKE_LOCK" tools:node="replace" />
.
Update: in recent versions of ACRA library that unfortunate "feature" has been removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With