【发布时间】:2014-08-20 09:50:35
【问题描述】:
我有一个启动相机意图的应用程序,以便用户可以拍照。拍摄照片后,它会保存在特定文件夹的外部存储中。问题是我在画廊里看不到它。你有什么建议吗?我应该在 onActivityResult() 中做些什么吗?如果是,是什么?
这是代码(我使用了 android 文档中的代码):
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;
}
【问题讨论】:
标签: android android-camera android-gallery android-camera-intent