![](/img/trans.png)
[英]MediaStore.Audio.Media.EXTERNAL_CONTENT_URI return an empty cursor
[英]MediaStore.Images.Media.INTERNAL_CONTENT_URI returns empty cursor
我有代码通过MediaStore.Images.Media.EXTERNAL_CONTENT_URI
从外部获取所有图像,并通过相同的方式获取内部(但内部而不是外部)
在我的设备android版本7.0中,外部光标返回的外部和内部所有图像,就像问题标题内部返回的空光标一样,我100%表示内部有很多图像
Big Strange Prob ,同一代码可与另一台设备android 5.1版正常工作,内部返回内部图像,外部返回其自身的img,所以问题出在哪儿我不明白...
同一代码在2个真实设备上的工作方式不同(此处没有仿真器)
两个游标的代码如下
cursorEx = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, null, null, DATE_DESC_SORT_ORDER);
cursorIn = getContentResolver().query(MediaStore.Images.Media.INTERNAL_CONTENT_URI,
projection, null, null, DATE_DESC_SORT_ORDER);
可能您未在android 7中请求权限。它是强制性的! 您可以请求权限,也可以定位小于22的SDK。
if (ContextCompat.checkSelfPermission(ProfileActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(ProfileActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Explain to the user why we need to read the contacts
}
ActivityCompat.requestPermissions(ProfileActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST);
// MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
// app-defined int constant that should be quite unique
return;
}else {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent,
"Selecione a foto "), select_image_code);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.