安卓权限问题

怎么获取权限的详情,安卓有这个api吗
打个比方,传一个"android.permission.ACCESS_FINE_LOCATION"返回权限名称"定位"和权限解释"通过网络或者卫星对您的手机定位"
感觉自己写好麻烦,大概翻了一下安卓API文档没找到

阅读 3.1k
2 个回答

明显有这样的 API: PermissionInfo
以 kotlin 为例使用如下代码.

        val permissionInfo =  packageManager.getPermissionInfo("android.permission.ACCESS_FINE_LOCATION", PackageManager.GET_META_DATA)
        val desc = permissionInfo.loadDescription(packageManager)
        val label = getString(permissionInfo.labelRes)
        println("name:${permissionInfo.name}")
        println("desc:${desc}")
        println("label:${label}")

输出如下:(因为我是在模拟器下跑的,默认是英文)

11-25 03:42:07.604 I/System.out: name:android.permission.ACCESS_FINE_LOCATION
11-25 03:42:07.604 I/System.out: desc:This app can get your location based on GPS or network location sources such as cell towers and Wi-Fi networks. These location services must be turned on and available on your phone for the app to be able to use them. This may increase battery consumption.
11-25 03:42:07.605 I/System.out: label:access precise location (GPS and network-based)

应该没有类似的 API,因为本身定义一个权限本身就没有太多内容,更没有详情。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题