发出许可请求后,无法在棉花糖中获取位置 [英] cannot fetch location in marshmallow after giving permission request
本文介绍了发出许可请求后,无法在棉花糖中获取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个位置应用程序,该功能在除棉花糖以外的所有设备上都可以正常工作.我在运行时已请求权限,并且在我授予权限时未获取经度和纬度,如果我要进行设置并从高精度更改位置为了节省电池电量,可以提取位置并运行该应用程序.我希望以高精度获取位置.
I am developing an location app which is working fine in all devices except in Marshmallow.I have requested permission during runtime and when I grant permission longitude and latitude is not fetched,if i go to settings and change the location from high accuracy to battery saving,location is fetched and the app works.I want location to be fetched at high accuracy.
ActivityCompat.requestPermissions(this,
new String[]{
Manifest.permission.CAMERA,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.INTERNET,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WAKE_LOCK,
},
1);
推荐答案
尝试一下
第1步:-在manifyingr文件中添加此权限
step 1 :- add this permission in manifiesr file
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
第2步:要求运行时权限
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);
}
第3步:处理渗透结果
@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_msg, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, location_permission_not_granted_msg, Toast.LENGTH_SHORT).show();
}
}
}
这篇关于发出许可请求后,无法在棉花糖中获取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文