如果我只在 Google Play 商店发布,我是否需要 android.permission.WAKE_LOCK 用于 Google Play 服务?

Do I need android.permission.WAKE_LOCK for Google Play Services if I only release in Google Play Store?

我正在尝试为 Android 集成 Google 分析。根据 documentation here, it asks to add android.permission.WAKE_LOCK (provides the comment note below). I dont understand it clearly. If I am releasing the app ONLY in the Google Play Store,我还需要这个吗?

如果不是绝对必要的话,我真的不想要求用户额外的许可。

<!-- Optional permission for reliable local dispatching on non-Google Play devices -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

特别是,我不明白这个注释到底是什么意思here:

Optionally a WAKE_LOCK permission can be requested to improve dispatching on non-Google Play devices.

WAKE_LOCK

Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming.

在 Google Play 设备上,后台服务几乎总是 运行 和 "Google Play Services",因此不需要 WAKE_LOCK

在非Google Play 设备上,WAKE_LOCK 有助于保持 Google Analytics 的调度过程/服务处于活动状态,因此它有更多机会报告/上传数据。

编辑

Also, it is unclear what happens to dangerous permissions in permission groups that are not ones that the user can control via Settings, such as SYSTEM_TOOLS.

https://commonsware.com/blog/2015/06/02/random-musings-m-developer-preview-bad.html

更新:从Android 6开始(API 23级,WAKE_LOCK被归类为“normal”权限,意思是权限是自动授予的。删除 WAKE_LOCK 权限通常会导致应用程序崩溃(见下文),所以我会避免这样做。


我也是一样的情况。我不想添加额外的权限,因为它会显着减少使用最新版本应用程序的人数(因为新权限意味着用户必须明确选择接收应用程序更新)。

我相信我已经通过结合 this SO question 上的一些答案找到了解决方案。

首先,将 "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 时,我可以看到不再需要权限:

重要

看来此解决方案可能不再可行。我现在收到大量 RuntimeExceptions 消息 "Neither user 10182 nor current process has 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.

删除 WAKE_LOCK 时,还要删除 AnalyticsReceiver 和 AnalyticsService。

这种方式写在这个网站上。 http://coffeee.hatenablog.com/entry/2017/11/26/035828

  1. 打开AndroidManifest.xml
  2. 单击 "Marged Manifest" 的选项卡
  3. 右键单击 WAKE_LOCK 并删除
  4. 删除 AnalyticsReceiver 和 AnalyticsService

祝你好运