简体   繁体   English

在Android棉花糖中集成新权限

[英]Integrate new permission in android marshmallow

众所周知,api级别23(Android Marshmallow)已进行了一些更改,在该级别中,我们必须在运行时请求一些处于危险级别的权限,例如摄像头,读/写外部存储等。是否有任何方法可以获取来自AndroidManifest文件的细化权限?

Android Marshmallow introduces an entirely new spin on application permissions,Users now have the ability to revoke runtime permissions whenever they desire. Android Marshmallow引入了全新的应用程序权限旋转,用户现在可以随时根据需要撤消运行时权限。 This means that you can't assume the app has access to the permission, even if it had been granted previously. 这意味着您无法假定该应用程序有权访问该权限,即使该权限先前已被授予也是如此。 You can refer this lib or this guide .I Hope this will help you out. 您可以参考此lib或本指南 。希望对您有所帮助。

1) You can get all the permissions given in your app using android api functions. 1)您可以使用android api函数获取应用程序中提供的所有权限。

2) Then you can make a constant HashMap of dangerous permissions (which you are calling granular i guess). 2)然后,您可以使危险权限的常量HashMap(我猜这是粒度)。

3) When you will get all the permissions of your app just compare each permission individually either is it present in Dangerous Permissions HashMap or not. 3)当您获得应用程序的所有权限时,只需分别比较每个权限,无论它是否存在于危险权限HashMap中。

Happy Coding :) 快乐编码:)

Requesting permission is quite monotonous. 请求许可非常单调。 One have to check permission each and every time whenever you use. 无论何时使用,都必须每次都要检查权限。 For simplicity you can use PermissionAcceptor-master library. 为简单起见,您可以使用PermissionAcceptor-master库。

Almost all permission is included in this library. 几乎所有权限都包含在此库中。

You have to add few lines of code using PermissionAcceptor-master library like 您必须使用PermissionAcceptor-master库添加几行代码,例如

new PermissionRequest(MainActivity.this,
        Permission.PERMISSION_CAMERA,
        PermissionCode.CODE_PERMISSION_CAMERA,
        R.string.permission_camera_rationale,
        R.string.permission_camera_denied,
        R.string.permission_enable_message, this)
        .checkPermission();

For more information, visit PermissionAcceptor-master . 有关更多信息,请访问PermissionAcceptor-master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM