【发布时间】:2012-01-07 17:17:47
【问题描述】:
我正在使用以下代码将图像保存到 SD 卡。
但是如何获取保存图像的图像路径,因为我想使用此路径在下一个活动中为 ImageView 设置图像。
我尝试使用onActivityResult(),但无法获得路径。
onActivitySesult()only 仅在我们想要打开浏览文件的意图时触发,但我想在不打开画廊或意图获取文件路径的情况下访问。
任何观点都会有所帮助。
期待你的答复。
谢谢。
PictureCallback myPictureCallback_JPG = new PictureCallback(){
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub
FileOutputStream outStream = null;
try {
// Write to SD Card
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg",System.currentTimeMillis()));
outStream.write(arg0);
outStream.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
Toast.makeText(Photo.this, "Image Saved to SD Card", Toast.LENGTH_SHORT).show();
System.out.println();
} catch (FileNotFoundException e) {
e.printStackTrace();
//Log.e("Photo", "Image files get saved in SD Card only",e);
} catch (IOException e) {
e.printStackTrace();
}
camera.startPreview();
}};
【问题讨论】:
标签: android