Android 相机不显示打开的画廊只有在重启时才有效phone
Android Camera does not show open gallery only works when restart phone
我正在尝试在 android 自定义相机中打开图库。但是它会在重启时显示并保存 sdcard phone。我的代码有什么问题?
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
我不明白这个问题,你是问为什么打开图库按钮只有在你重启时才显示 phone 或者为什么照片只有在重启后才能显示?
如果是后者,请尝试调用媒体扫描器。在 Toast 之前或之后。
public void addPictureToGallery(String fileName) {
File f = new File(fileName);
Uri contentUri = Uri.fromFile(f);
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,contentUri);
sendBroadcast(mediaScanIntent);
}
我正在尝试在 android 自定义相机中打开图库。但是它会在重启时显示并保存 sdcard phone。我的代码有什么问题?
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
我不明白这个问题,你是问为什么打开图库按钮只有在你重启时才显示 phone 或者为什么照片只有在重启后才能显示?
如果是后者,请尝试调用媒体扫描器。在 Toast 之前或之后。
public void addPictureToGallery(String fileName) {
File f = new File(fileName);
Uri contentUri = Uri.fromFile(f);
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,contentUri);
sendBroadcast(mediaScanIntent);
}