Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get WAKE_LOCK permission on Android 8 Oreo

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.
like image 563
Greg Dan Avatar asked Jun 21 '18 15:06

Greg Dan


People also ask

How do I enable wake lock permissions?

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.

What is WakeLock permission android?

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.

How do I grant permission to write on android?

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.


1 Answers

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.

like image 78
Greg Dan Avatar answered Oct 19 '22 03:10

Greg Dan