Android Marshmallow中的运行时权限检查(Runtime permission check in Android Marshmallow)

系统教程 行业动态 更新时间:2024-06-14 16:57:39
Android Marshmallow中的运行时权限检查(Runtime permission check in Android Marshmallow)

关于Marshmallow,如何判断Android中哪些操作系统调用需要权限检查? 对于某些位置管理器调用,如果在调用之前未检查权限,则编译器将显示错误。 但是,有很多其他操作系统调用需要权限,但如果在调用之前未检查权限,则不会生成编译器错误。

例如,我在我的一个应用程序中调用了位置管理器的sendExtraCommand方法。 编译器在调用之前没有给出任何需要权限检查的指示,因此我没有。 当我将鼠标悬停在Android Studio中的调用上时,文档窗口中的信息不会显示调用所需的权限。 但是当Marshmallow用户开始使用我的应用程序时,他们就会遇到安全性异常。

它只是我,还是Marshmallow的安全性极其糟糕?

这里有一个类似的问题,但它没有任何好的答案,所以我创建了这个问题,希望问题能得到更多关注: 如何在代码中找到所需的Android Marshmallow运行时权限?

With respect to Marshmallow, how do I tell which operating system calls in Android require a permission check? For some of the Location Manager calls, the compiler will show an error if I don't check permissions before the call. But there are lots and lots of other operating system calls for which permissions are required but which do not generate a compiler error if the permission is not checked before the call.

For example, I have a call to the Location Manager's sendExtraCommand method in one of my apps. The compiler doesn't give any indication that a permission check is required before the call, so I didn't have one. When I mouse over the call in Android Studio, the information in the documentation window doesn't give any indication that permissions are required for the call. But when Marshmallow users started using my app, they were getting security exceptions.

Is it just me, or is the Marshmallow security thing extremely poorly thought out?

There is a similar question here, but it doesn't have any good answers, so I have created this one in the hope that the issue will get more attention: How to find required Android Marshmallow runtime permissions in code?

最满意答案

如何判断Android中哪些操作系统调用需要权限检查?

如您所知,在某些情况下,您可能会收到Lint警告等。 人们想象这会随着时间的推移而改善。

在其他情况下,您阅读JavaDocs,其中类或方法提到您需要权限。 将<uses-permission>元素添加到清单时,还要考虑这是否是需要在运行时处理的dangerous权限之一 。

除此之外,您可以在测试应用程序时发现测试失败。

如果您发现这些不足,请将targetSdkVersion设置为22或更低,直到您对Android的运行时权限支持更加满意为止。

how do I tell which operating system calls in Android require a permission check?

As you note, in some cases, you may get Lint warnings and the like. One imagines that this will improve over time.

In other cases, you read the JavaDocs, where the class or method mentions that you need a permission. When you add the <uses-permission> element to your manifest, also think about whether that is one of the dangerous permissions that requires handling at runtime.

Beyond that, you find out when you test your app and your tests fail.

If you find those to be insufficient, set your targetSdkVersion to 22 or lower, until such time as you are more comfortable with Android's runtime permission support.

更多推荐

本文发布于:2023-04-13 12:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/11a86c4c976bda9b5f8c1e2ace1f5972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:权限   Marshmallow   Android   check   permission

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!