【发布时间】:2016-03-13 21:51:48
【问题描述】:
我正在尝试在 API 23 上的 google MapsActivity 上使用 android 定位服务。我在清单文件中拥有这样的权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
当我尝试使用时:
mMap.setMyLocationEnabled(true);
它显示生成权限检查代码的错误(如下)。而且我不知道在块中输入什么;似乎条件语句已经在进行必要的检查。
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
似乎我在此条件中输入的任何内容都会导致错误。
【问题讨论】:
-
看看这个答案中的代码:stackoverflow.com/a/34774869/4409409
标签: android permissions gps location maps