权限未询问

时间:2018-12-04 13:53:26

标签: android permissions manifest

我想知道为什么在启动应用程序时不询问我的权限,这是我的清单权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

当我浏览手机的参数时,我仅具有“位置”权限(并且已禁用)。

4 个答案:

答案 0 :(得分:1)

如果未按权限询问您,则意味着没有提示用户允许Internet权限,这很正常。 Internet在常规权限列表中,因此是自动授予的。有关正常权限的更多信息,请查看:https://developer.android.com/guide/topics/permissions/normal-permissions.html

此外,添加权限是一个分为两个步骤的过程;在清单中声明需要的权限后,还必须在Java文件中进行一些设置。看看https://developer.android.com/training/permissions/requesting

此外,如果您正在寻找更简单的方法来处理权限,那么那里也有类似的库,例如RxPermissions:https://github.com/tbruyelle/RxPermissions

希望这会有所帮助!

答案 1 :(得分:0)

您应该请求运行时权限 请参阅文档: Request App Permissions

答案 2 :(得分:0)

如果您定位的是SDK 26+,则需要检查以下代码中的权限:

if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.ACCESS_FINE_LOCATION)
    != PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
        Manifest.permission.ACCESS_FINE_LOCATION)) {
    // Show an explanation to the user *asynchronously* -- don't block
    // this thread waiting for the user's response! After the user
    // sees the explanation, try again to request the permission.
} else {
    // No explanation needed, we can request the permission.
    ActivityCompat.requestPermissions(thisActivity,
            arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
            MY_PERMISSIONS_ACCESS_FINE_LOCATION)

    // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
    // app-defined int constant. The callback method gets the
    // result of the request.
}
} else {
// Permission has already been granted - or running on old Android
}

它在Request App Permissions

中有描述

答案 3 :(得分:0)

对于棉花糖(API 23)及更高版本,您不仅应该在清单中而且在代码中都应获得位置,电话状态和其他dangerous permissions的许可(运行时许可)。对于其他许可,清单就足够了。

请参见this video 您也可以在this Q&A

中找到您的解决方案