此代码在SD卡中创建文件夹但不保存该文件夹中的图像我是怎么做到的?在defualt gellry中显示图像我想在我的“myfolder23”中保存图像而不是默认gellry我是怎么做到的?我如何只在“myfolder23”中保存相机拍摄的图像而不是默认的gellry文件夹?或者从默认的gellery中删除只保存在“myfolder23”???
private void startDialog() {
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
myAlertDialog.setTitle("Upload Pictures Option");
myAlertDialog.setMessage("How do you want to set your picture?");
myAlertDialog.setPositiveButton("Gallery", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
pictureActionIntent = new Intent(Intent.ACTION_GET_CONTENT,
null);
pictureActionIntent.setType("image/*");
pictureActionIntent.putExtra("return-data", true);
startActivityForResult(pictureActionIntent, GALLERY_PICTURE);
}
});
myAlertDialog.setNegativeButton("Camera", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
pictureActionIntent = new
Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String newFolder = "/myFolder23";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File file = new File(extStorageDirectory + newFolder);
file.mkdir();
Uri outputFileUri = Uri.fromFile(file);
pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(pictureActionIntent, CAMERA_PICTURE);
}
});
myAlertDialog.show();
}
答案 0 :(得分:0)
更改您的代码,就像在SD卡上存储文件一样:
public final String SDCARD_ROOT_PATH =
Environment.getExternalStorageDirectory().getAbsolutePath();
public final String SAVE_PATH_IN_SDCARD = "/myFolder23/";
public final String IMAGE_CAPTURE_NAME
="imgtemp"+System.currentTimeMillis()+".png";
File dir = new File(Environment.getExternalStorageDirectory() + "/myFolder23");
if(dir.exists() && dir.isDirectory()) {
// do something here
}
else{
//create dir here
dir.mkdir();
}
Intent pictureActionIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new
File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD,IMAGE_CAPTURE_NAME)));
startActivityForResult(pictureActionIntent,CAMERA_PICTURE);