我注意到打开活动后,图块UI元素上未显示图块。新的Android版本8.1就是这种情况。
您知道可能是什么问题吗?
是否有任何新的应用权限需要声明?
答案 0 :(得分:2)
OSMDroid映射需要外部存储权限。即使将其添加到清单文件中,如果api级别> 23
,用户也需要在运行时手动授予权限@Override public void onCreate(Bundle savedInstanceState) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
//app has permissions, do your normal job here.
} else {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
}
以及请求许可结果
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//refresh view or recreate the Activity
}
}
}