【问题标题】:How to find required Android Marshmallow runtime permissions in code?如何在代码中找到所需的 Android Marshmallow 运行时权限?
【发布时间】:2016-04-13 06:35:48
【问题描述】:

我正在准备我的应用以针对 Android 6.0 Marshmallow。

将目标 api 设置为 23 时,应用程序在启动时立即崩溃。 logcat 输出中没有有用的信息。 (它给出了一个“请求的窗口不存在”IllegalStateException,但仍然没有像类名或行号这样真正有用的东西。)

这很好(不是真的),我最终将其缩小到我的启动活动,在那里我获得了用户的设备 IMEI 代码 (TelephonyManager.getDeviceId())。需要添加运行时权限请求。我明白这一点。

但是,该应用有大约 60 个类,涉及众多活动,因此需要整理大量代码。我如何才能搜索代码以找到需要运行时权限的所有情况?

Google 肯定想到了一种简单的方法让开发人员可以跟踪需要权限请求的位置?我想也许注释掉清单中的权限会触发使用权限的编译时错误,或者类似的东西,但不是。

我目前的方法是浏览应用程序,当它崩溃时,对我的启动活动执行上述操作,然后非常缓慢地缩小它的位置。这是极其低效和耗时的。我很想暂时将其保留在 API 22 上,但我知道这迟早必须完成。

【问题讨论】:

  • 您好,您可以发送构建等级 XML 文件吗
  • 尝试分析 > 在 Android Studio 中检查代码。
  • 谢谢,但 Inspect Code 没有为此提供解决方案。
  • 你好试试这个 API 级别 23 stackoverflow.com/a/41221852/5488468

标签: android android-permissions android-6.0-marshmallow


【解决方案1】:

删除所有 AndroidManifest.xml 权限。
分析 -> 按名称运行检查 -> Android Studio 中的Constant and Resource Type Mismatches
可以检测权限。

但这种检测并不完美...
因为这仅检测包含此 xmls 文件的方法。
https://android.googlesource.com/platform/tools/adt/idea/+/master/android/annotations/android
https://android.googlesource.com/platform/tools/adt/idea/+/master/android/annotations/android/accounts/annotations.xml#118

【讨论】:

    【解决方案2】:

    对我有用的是: 分析 -> 按名称运行检查 -> 缺少权限

    【讨论】:

      猜你喜欢
      • 2016-07-16
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 2015-12-23
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多