gpt4 book ai didi

android - 错误权限 ACCESS_FINE_LOCATION

转载 作者:行者123 更新时间:2023-11-29 19:09:31 26 4
gpt4 key购买 nike

我正在使用权限 ACCESS_FINE_LOCATION 但是当运行时出现错误:需要 ACCESS_FINE_LOCATION 权限为什么?

提前致谢。

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

最佳答案

ACCESS_FINE_LOCATIONACCESS_COARSE_LOCATION 尝试获取位置时都需要权限 所以在 list 文件中添加这两个权限,如果你的目标是 android 6.0 及更高版本,而不是像下面的代码一样添加这个运行时权限

   String permission = android.Manifest.permission.ACCESS_FINE_LOCATION;
if (ActivityCompat.checkSelfPermission(SearchCityClass.this, permission)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.
checkSelfPermission(SearchCityClass.this, android.Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(SearchCityClass.this, new String[]
{permission}, PERMISSION_GPS_CODE);

}

现在处理许可结果

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_GPS_CODE) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {


Toast.makeText(this, "location_permission_granted ", Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(this, "location_permission_not_granted ", Toast.LENGTH_SHORT).show();
}
}

}

关于android - 错误权限 ACCESS_FINE_LOCATION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45857160/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com