有没有办法检查代码的清单权限?
如何通过代码检查manifest.xml 中的特定权限?如果我的应用程序缺少某些必需的权限,我想抛出一些异常。
例如、FINE_LOCATION
和 COARSE_LOCATION
我知道 android 也会在启动使用 GPS 的特定活动时抛出异常,但我需要检查清单并在应用程序本身启动时抛出异常。这不仅适用于位置访问,也适用于其他权限。
任何建议都会有帮助。
How do I check for a specific permission in the manifest.xml from code? I want to throw some exception if some permissions that are necessay for my application are missing.
For example, FINE_LOCATION
and COARSE_LOCATION
I know that android will also throw an exception on the launch of the specific activiy that is using GPS, but I need to check the manifest and throw an exception at the launch of the application itself. This holds not only for location access, but also for other permissions.
Any suggestions would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用PackageManager检查特定权限是否被授予权限。例如
You can check whether the permission is granted or not for specific permission by using PackageManager. For example
您可以使用以下命令在运行时读取可用的
标记。在较旧的 Android 版本以及 Android 6 和 7 上进行了测试You can read the available
<uses-permission>
tags at runtime using the following. Tested on older Android versions AND Android 6 and 7