当我点击按钮时相机捕获图像但无法保存在SD卡中。请检查此代码。如果我有任何错误
` ImgPhoto =(ImageView)findViewById(R.id.imageView1);
BtnSelectImage = (Button) findViewById(R.id.button1);
BtnSelectImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
try {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Couldn't load photo", Toast.LENGTH_LONG).show();
}
}
});
}
private void SaveIamge(Bitmap finalBitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File file1=new File(Environment.getExternalStorageDirectory()+File.separator+"image.jpeg");
File myDir = new File(root + "/sdcard/");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpeg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
sendBroadcast(new Intent(
Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
}
}`
答案 0 :(得分:1)
按下后退按钮时,将调用当前活动的onBackPressed()方法。默认行为是完成活动。您不应该做任何事情来启用此行为。
答案 1 :(得分:1)