[英]Camera Intent: Picture missing in gallery
I have an app that starts a camera intent so the user can take a picture. 我有一个可以启动相机意图的应用程序,以便用户可以拍照。 After the picture is taken it is saved on the external storage in a specific folder.
拍照后,照片将保存在外部存储中的特定文件夹中。 The problem is that I can't see it in the gallery.
问题是我在图库中看不到它。 Do you have any suggestions?
你有什么建议吗? Should I do something in onActivityResult()?
我应该在onActivityResult()中做些什么吗? If yes, what?
如果是,那是什么?
Here is the code (I used the code from android docs): 这是代码(我使用了android docs中的代码):
public void takePicture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
@SuppressLint("SimpleDateFormat")
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
String imageFileName = "IMG_" + timeStamp + "_";
File imageFile = new File(Environment.getExternalStorageDirectory()
+ "/LocalSin");
if (!imageFile.exists()) {
imageFile.mkdirs();
}
File image = File.createTempFile(imageFileName, ".jpg", imageFile);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
Use this code after taking picture. 拍照后使用此代码。
public void addPicInGalery()
{
Intent scan= new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File file=new File(path); // destination path where u want to store image
Uri uri=Uri.fromFile(file);
scan.setData(uri);
getActivity().sendBroadcast(scan);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.