[英]this code create folder in SD card but not save image in that folder
此代碼在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();
}
更改代碼以將文件存儲在sdcard上:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.