ACCESS_COARSE_LOCATION和ACCESS_FINE_LOCATION:
android.permission.ACCESS_COARSE_LOCATION:是基站定位,即基于无线网络进行定位;
android.permission.ACCESS_FINE_LOCATION:是GPS定位,根据设备位置信息定位。
请求定位权限(两个都请求):
private void getPermission() {
//检查权限是否存在
if (ContextCompat.checkSelfPermission(MainActivity_B.this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(MainActivity_B.this,
Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED)
{
//向用户申请授权
ActivityCompat.requestPermissions(this,
new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
}, 1);
}
}