这code SD卡中创建文件夹,但不能保存图像该文件夹中 [英] this code create folder in SD card but not save image in that folder

查看:171
本文介绍了这code SD卡中创建文件夹,但不能保存图像该文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code创建SD卡的文件夹,但不能保存图像文件夹中我该怎么办?是显示图像defualt gellry我想保存的图像在我的myfolder23不是在默认gellry我是怎么做的?怎么我只保存相机拍摄的图像中的myfolder23不是默认的文件夹gellry?或默认gellery只删除保存在myfolder23???

 私人无效startDialog(){
        AlertDialog.Builder myAlertDialog =新AlertDialog.Builder(本);
        myAlertDialog.setTitle(上传的图片选项);
        myAlertDialog.setMessage(你要设置你的照片吗?);        myAlertDialog.setPositiveButton(画廊,新
  DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface为arg0,ARG1 INT){
                pictureActionIntent =新意图(Intent.ACTION_GET_CONTENT,
     空值);
                pictureActionIntent.setType(图像/ *);
                pictureActionIntent.putExtra(回归数据,真正的);
                startActivityForResult(pictureActionIntent,GALLERY_PICTURE);
            }
        });        myAlertDialog.setNegativeButton(照相机,新
   DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface为arg0,ARG1 INT){
                pictureActionIntent =新
    意图(android.provider.MediaStore.ACTION_IM​​AGE_CAPTURE);
                字符串newFolder =/ myFolder23;
                。字符串extStorageDirectory = Environment.getExternalStorageDirectory()的toString();
                档案文件=新的文件(extStorageDirectory + newFolder);
                file.mkdir();
                乌里outputFileUri = Uri.fromFile(文件);             pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri);                startActivityForResult(pictureActionIntent,CAMERA_PICTURE);
            }
        });
        myAlertDialog.show();
    }


解决方案

更改code作为存储SD卡上的文件:

 公共最后弦乐SDCARD_ROOT_PATH =
           Environment.getExternalStorageDirectory()getAbsolutePath()。
公共最后弦乐SAVE_PATH_IN_SDCARD =/ myFolder23 /;
公共最后弦乐IMAGE_CAPTURE_NAME
                            =imgtemp+ System.currentTimeMillis的()+PNG;文件DIR =新的文件(Environment.getExternalStorageDirectory()+/ myFolder23);
如果(dir.exists()及&放大器; dir.isDirectory()){
  //这里做什么
 }
其他{
    //创建目录这里
    dir.mkdir();
   }
 意图pictureActionIntent =新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
 pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(新
         文件(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD,IMAGE_CAPTURE_NAME)));  startActivityForResult(pictureActionIntent,CAMERA_PICTURE);

this code create folder in SD card but not save image in that folder how i do that? is show images in defualt gellry i want to save image in my "myfolder23" not in default gellry how i did that??? how i only save camera taken images in"myfolder23" not in default gellry folder? or delete from default gellery only save in "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();
    }

解决方案

Change your code as for storing file on 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);  

这篇关于这code SD卡中创建文件夹,但不能保存图像该文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆