【发布时间】:2019-05-24 04:53:40
【问题描述】:
我正在为我的应用程序制作自定义应用程序厨房。从我的自定义相机捕获图像并将图像保存在位于 Environment.DIRECTORY_PICTURES 中的 xyz 目录中。我想访问所有这些图像并在自定义厨房回收站视图中显示。我尝试了很多方法,但无法获取图像。提前帮助我修复此功能。
File fileX = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(), "xyz");
projection = new String[]{MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
Cursor cursor = getContentResolver().query(FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", fileX),
projection, null, null,null);
// private final String[] projection = new String[]{ MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
if (cursor == null) {
message = handler.obtainMessage();
message.what = commonVariables.ERROR;
message.sendToTarget();
return;
}
ArrayList<Image> temp = new ArrayList<>(cursor.getCount());
File file;
folders = new ArrayList<>();
if (cursor.moveToLast()) {
do {
if (Thread.interrupted()) {
return;
}
long id = cursor.getLong(cursor.getColumnIndexOrThrow(projection[0]));
String name = cursor.getString(cursor.getColumnIndexOrThrow(projection[1]));
String path = cursor.getString(cursor.getColumnIndexOrThrow(projection[2]));
String bucket = cursor.getString(cursor.getColumnIndexOrThrow(projection[3]));
DebugLog.e("MSG: PATH = > " + name );
// file = new File(path);
// DebugLog.e("MSG: Absolute PATH = > " + file.getAbsolutePath());
// if (file.exists()) {
// Image image = new Image(id, name, path, false);
// temp.add(image);
//
// if (folderMode) {
// Folder folder = getFolder(bucket);
// if (folder == null) {
// folder = new Folder(bucket);
// folders.add(folder);
// }
//
// folder.getImages().add(image);
// }
// }
它给了我参数异常_ID不存在。
【问题讨论】:
标签: android android-image android-gallery android-cursor