更新:截至Android 6(API级别23),WAKE_LOCK被列为“普通”权限,这意味着该权限会自动授予。移除WAKE_LOCK权限往往会导致应用程序崩溃(请参见下文),因此我建议避免这样做。
我处于同样的位置。我不想添加额外的权限,因为这将显著减少使用最新版本应用程序的人数(因为新权限意味着用户必须明确选择接收应用程序更新)。
我相信我已经通过结合这个SO问题上的一些答案找到了解决方案。
首先,在应用程序清单中添加“tools”命名空间
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
其次,添加“WAKE_LOCK”权限,但使用删除选项
<uses-permission android:name="android.permission.WAKE_LOCK" tools:node="remove" />
现在,当我上传一个新的APK时,我可以看到没有再需要这个权限:
![wake lock permission removed](https://istack.dev59.com/flGEU.webp)
重要提示
似乎这个解决方案现在可能不可行了。我现在得到了大量的RuntimeExceptions,其消息为“用户10182和当前进程都没有android.permission.WAKE_LOCK权限”。
Fatal Exception: java.lang.RuntimeException
Unable to start receiver com.google.android.gms.measurement.AppMeasurementReceiver: java.lang.SecurityException: Neither user 10182 nor current process has android.permission.WAKE_LOCK.