我想在android中獲取ACCESS_FINE_LOCATION和ACCESS_COARSE_LOCATION的權限,但無論出於何種原因,它只授予ACCESS_COARSE_LOCATION的權限。在android中無法獲得ACCESS_FINE_LOCATION權限
我的活動:
final int PERMISSION_ALL = 1;
String[] PERMISSIONS = {ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION};
if(!hasPermissions(this, PERMISSIONS)){
System.out.println("=========================================nottttt========================================================");
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
@Override
public void onRequestPermissionsResult(int requestCode, String PERMISSIONS[], int[] grantResults) {
System.out.println("==================requesttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt");
switch (requestCode) {
case PERMISSION_ALL: {
System.out.println("lengthhhhhhhhhhhhhhhhhhhhhh"+PERMISSIONS.length);
for (int i = 0; i < PERMISSIONS.length; i++) {
String permission = PERMISSIONS[i];
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
System.out.println(permission + "is alreadyyyyyyyyyyyyy grantedddddddddddddddd");
} else {
System.out.println(permission + "is not grantedddddddddddddddd");
}
return;
}
}
}
}
public static boolean hasPermissions(Context context, String[] permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
Android清單:
<user-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<user-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我啓動應用程序,提示我分給位置訪問,我選擇是的,但ACCESS_FINE_LOCATION不granted.Can有人幫我找到問題?
沒有進一步的修改,突然它說罰款位置授予這是OK。有誰知道爲什麼會出現這種奇怪的行爲? –