我使用了以下意图:
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);基本上,我使用ACTION_IMAGE_CAPTURE intent来调用相机并将拍摄的图像保存到指定的uri中。
它可以工作,但同时图像也会以默认名称保存。
因此,一旦我抓拍了图片,它就会被保存两次,分别保存在uri和默认路径和名称中。
如何确保它只保存在指定的uri中?
提前谢谢你,Perumal
发布于 2012-01-31 00:38:17
您可以获取图库最后一张图像的ID或绝对路径。然后把它删除。
可以这样做:
/**
* Gets the last image id from the media store
* @return
*/
private int getLastImageId(){
final String[] imageColumns = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA };
final String imageOrderBy = MediaStore.Images.Media._ID+" DESC";
Cursor imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);
if(imageCursor.moveToFirst()){
int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
String fullPath = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
Log.d(TAG, "getLastImageId::id " + id);
Log.d(TAG, "getLastImageId::path " + fullPath);
imageCursor.close();
return id;
}else{
return 0;
}
}并删除该文件:
private void removeImage(int id) {
ContentResolver cr = getContentResolver();
cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media._ID + "=?", new String[]{ Long.toString(id) } );
}这段代码基于帖子:Deleting a gallery image after camera intent photo taken
https://stackoverflow.com/questions/7109457
复制相似问题