0

此代码在 SD 卡中创建文件夹,但不将图像保存在该文件夹中,我该怎么做?是在默认凝胶中显示图像我想将图像保存在我的“myfolder23”中而不是默认凝胶中我是怎么做到的???我如何只将相机拍摄的图像保存在“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();
    }
4

1 回答 1

0

更改代码以将文件存储在 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);  
于 2012-12-18T07:58:20.453 回答