0

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();
    }
Hayya ANAM
  • 575
  • 2
  • 14
  • 38

1 Answers1

0

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);  
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • this error occur for Strings Illegal modifier for parameter SAVE_PATH_IN_SDCARD; only final is permitted – Hayya ANAM Dec 18 '12 at 08:00
  • @HayyaAnam : just declare all these variable at class level or add final with it – ρяσѕρєя K Dec 18 '12 at 08:02
  • ok i paste on top of class all String now no error now i m try to deploy and compile wait n thnx – Hayya ANAM Dec 18 '12 at 08:04
  • is still not save image in myfolder23 only create folder just – Hayya ANAM Dec 18 '12 at 08:07
  • yes now is save image in myfolder23 thnx but is also save in mobile default gellry how do i remove from there? only save in myfolder23??? – Hayya ANAM Dec 18 '12 at 08:15
  • @HayyaAnam : i have already comment you in your last question after storing in database just delete it from sdcard or from MediaStore ContentProvider. – ρяσѕρєя K Dec 18 '12 at 08:18
  • @HayyaAnam : have you got me what i'm saying? – ρяσѕρєя K Dec 18 '12 at 08:19
  • @HayyaAnam : HaHa :) just put `File file = new File(FilePath);boolean deleted = file.delete();` for deleting file . and tell me what happen bez i think this will delete your file from both place – ρяσѕρєя K Dec 18 '12 at 08:23
  • @HayyaAnam : this is not possible i'm sure this is not possible you can directly tell this to BOSS – ρяσѕρєя K Dec 18 '12 at 08:26
  • @HayyaAnam : yes if you have any file in following formates like .png,.jpg,.ttf etc. these files must appear in gallery . if you have real device then check it manually – ρяσѕρєя K Dec 18 '12 at 08:30
  • im not very good in programining check this post what this say in last? http://stackoverflow.com/questions/6390163/deleting-a-gallery-image-after-camera-intent-photo-taken is possible or not delete duplicate image?? – Hayya ANAM Dec 18 '12 at 08:31
  • @HayyaAnam : ok it's not possible but if you think so then try it as link provided by you read accepted answer he is saying it's device specific . so i think 5% device support this type of future. – ρяσѕρєя K Dec 18 '12 at 08:35
  • @ρяσѕρєяK can u please help me i have images in my assets folder onClick of button i want to save image in external storage folder how can i create folder and save image from my assets folder to external storage folder – Erum Feb 21 '14 at 09:03