android - API >23 中未显示开放街道地图
问题描述
我对 osmdroid 库很陌生!我正在尝试制作一个应用程序(导航器)来检测并提醒用户有关特殊事件的信息。
我关注了 osmdroid wiki,并成功添加了低 API 的地图,但在 8.0(API 26)中,地图没有显示。我尝试添加权限,但地图一直没有显示,尽管它请求位置权限。你能建议我一个解决方案吗?在较低的 API 中,它可以完美运行。
if (Build.VERSION.SDK_INT < 23) {
} else {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != 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.
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},2);
} else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(grantResults.length>0 && grantResults[0]== PackageManager.PERMISSION_GRANTED){
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)==PackageManager.PERMISSION_GRANTED){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
}
}
根据 osmwiki,更高的 API 需要请求 WRITE_EXTERNAL_STORAGE、ACCESS_COARSE_LOCATION、ACCESS_FINE_LOCATION 权限。
解决方案
推荐阅读
- java - 我们可以在 javafx 中的多个类之间创建回调吗
- ruby-on-rails - 如何在 Rails 应用程序中为每个模型实例设置不同的 URL
- r - R shinyDashboard:添加超过 5 种有效状态/需要更多颜色
- java - Linux 更新后 Eclipse 不启动
- javascript - 使用 VBA 填充快速搜索栏
- javascript - HTML 5 音频播放器剩余时间显示延迟
- javascript - 使用 axios 和 JavaScript 在表格中上传图像并指示响应
- sql - 查找 Postgres/Sequelize 重复别名错误的来源(代码 42712)
- php - iCal 未显示组织者的会议时间段
- python - 计算numpy数组中的总和