拍的图片要机器断电后再浏览才有,如果不断电的话图库没更新
为什么我拍的图片要机器断电后再浏览才有,如果不断电的话图库没更新,我是调用系统图库看的。
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
photoview = (ImageView) findViewById(R.id.pic_view);
mCameraSurPreview = new CameraSurfacePreview(this);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mCameraSurPreview);
Button bReturnCamera = (Button) findViewById(R.id.bReturn_camera);
photoview.setOnClickListener(new View.OnClickListener()//返回功能菜单
{
public void onClick(View v)
{
Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
getAlbum.setType("image/*");
startActivityForResult(getAlbum, PHOTO_PICKED_WITH_DATA);
}
});
bReturnCamera.setOnClickListener(new Button.OnClickListener()//返回功能菜单
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(AndroidCameraActivity.this, FunctionMuenActivity.class);
startActivity(intent);
AndroidCameraActivity.this.finish();
}
});
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
//save the picture to sdcard
File pictureFile = getOutputMediaFile();
if (pictureFile == null){
Log.d(TAG, "图片存储失败");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
Toast.makeText(this, "Image has been saved to "+pictureFile.getAbsolutePath(),
Toast.LENGTH_LONG).show();
Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath(), null);
photoview.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
// Restart the preview and re-enable the shutter button so that we can take another picture
camera.startPreview();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_CAMERA:
//拍照
mCameraSurPreview.takePicture(this);
break;
}
// }
return true;
}
private File getOutputMediaFile(){
//get the mobile Pictures directory
File picDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
//get the current time
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return new File("/sdcard/DCIM/Camera" + File.separator + "IMAGE_"+ timeStamp + ".jpg");
}