如何在代码中找到所需的Android Marshmallow运行时权限? [英] How to find required Android Marshmallow runtime permissions in code?

查看:78
本文介绍了如何在代码中找到所需的Android Marshmallow运行时权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在准备针对Android 6.0棉花糖的应用.

I'm preparing my app to target Android 6.0 Marshmallow.

将目标api设置为23时,该应用在启动时立即崩溃. logcat输出中没有有用的信息. (它给出了请求的窗口不存在" IllegalStateException,但实际上,没有什么有用的东西,例如类名或行号.)

When setting the target api to 23, the app immediately crashes upon launch. There is no useful information in the logcat output. (It gives a "Requested window does not exist" IllegalStateException, but still, nothing actually useful like class name or line number.)

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

This is fine (not really), I eventually narrowed it down to my launch activity where I get the user's device IMEI code (TelephonyManager.getDeviceId()). There needs to be a runtime permission request added. I understand this.

但是,该应用程序在许多活动中都有大约60个类,因此有很多代码需要分类.如何查找代码以查找所有需要运行时权限的情况?

However, the app has something like 60 classes across numerous activities, so there is a lot of code to sort through. How can I possibly search through the code to find all of the cases where runtime permissions are required?

Google一定一定想出了一种简单的方法,使开发人员可以在何处查找到需要权限请求的地方?我以为,注释掉清单中的权限可能会触发使用权限的编译时错误,或者类似的情况,但是不行.

Surely Google must have thought of an easy way for developers to track down where the permission requests are required? I thought perhaps commenting out the permissions in the manifest would trigger a compile-time error where the permissions are used, or something of the sort, but nope.

我当前的方法是通过应用程序,当应用程序崩溃时,通过启动活动执行上述操作,并慢慢缩小其位置.这是极其低效且耗时的.我很想暂时将其保留在API 22中,但是我知道迟早要这样做.

My current method is by going through the app and when it crashes, do like the above with my launch activity and very slowly narrow down where it is. This is extremely inefficient and time-consuming. I'm tempted to just leave it at API 22 for now, but I know sooner or later this will have to be done.

推荐答案

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

Delete all AndroidManifest.xml permission.
Analyze -> Run Inspection by Name ->Constant and Resource Type Mismatches in Android Studio.
You can detect permission.

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

But this detection is not perfect...
Because this detects only method that contains this xmls files.
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

这篇关于如何在代码中找到所需的Android Marshmallow运行时权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆