拍的图片要机器断电后再浏览才有,如果不断电的话图库没更新

tw2429 2016-02-21 06:08:35
为什么我拍的图片要机器断电后再浏览才有,如果不断电的话图库没更新,我是调用系统图库看的。


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");
}
...全文
100 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tw2429 2016-02-22
  • 打赏
  • 举报
回复
是的,要通知。
wei220000 2016-02-21
  • 打赏
  • 举报
回复
public static void saveImageToGallery(Context context, Bitmap bmp) { File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee"); if (!appDir.exists()) { appDir.mkdir(); } String fileName = System.currentTimeMillis() + ".jpg"; File file = new File(appDir, fileName); try { FileOutputStream fos = new FileOutputStream(file); bmp.compress(CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); // Toast.makeText(context, "保存成功!", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), fileName, null); } catch (FileNotFoundException e) { e.printStackTrace(); } context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); } 要更新图库

80,359

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧