在我的应用程序上,我使用手机相机并将图像保存在 sd 卡上。问题是图片也被保存在手机内存中。有什么办法让我无法阻止吗?
这是启动相机意图的代码:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
这是将图像保存到 sd 卡的代码:
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/wardrobe_app");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
file_path = myDir.toString();
img_path = file_path + "/" + fname;
Toast t = Toast.makeText(addClothing.this,
img_path, Toast.LENGTH_LONG);
t.show();
这是将 ImageView 设置为拍摄图片的代码:
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
photo = (Bitmap) data.getExtras().get("data");
iv1.setImageBitmap(photo);
SaveImage(photo);
}
谢谢你的帮助!