我正在尝试打开我的照片,以便在手机的默认图库应用中查看它,但是当我这样做时,我的应用会闪烁并重新加载,而不会提供任何错误。我正在尝试像这样打开我的照片:
Uri uri = FileProvider.getUriForFile(context, "www.markwen.space.fileprovider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/jpg");
startActivity(intent);
我在这里找不到任何问题。我在想,如果我保存使用相机拍摄的照片时,我没有正确编码。当我保存照片时,我只需按照此处的说明进行操作:https ://developer.android.com/training/camera/photobasics.html
那么,你们用手机的相机应用程序拍照后如何保存照片呢?我该怎么做才能打开我的照片?谢谢
更新:
这是我拍照的方式:
private void startPhotoIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Create photo file
File photo = new File(getFileDirectory(".jpg"));
// Save intent result to the file
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getContext(), "www.markwen.space.fileprovider", photo));
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
// Start intent to take the picture
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
这是我保存拍摄照片的方式:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// Photo
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == -1) {
Uri imageUrl = data.getData();
if (imageUrl != null) {
// Announce picture to let other photo galleries to update
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(imageUrl);
getActivity().sendBroadcast(mediaScanIntent);
try {
MediaStore.Images.Media.insertImage(getContext().getContentResolver(), directory + filename, "Multimedia-Image", "Multimedia-Image");
Toast.makeText(getContext(), "Image saved to gallery", Toast.LENGTH_LONG).show();
filename = "";
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}