Android - Taking photos/video and saving them with a custom name to a custom destination via Intent work on some devices only why?

StackOverflow https://stackoverflow.com/questions/15976181

  •  03-04-2022
  •  | 
  •  

Question

This is the code i use to create the Intent:

try {
                    file = createImageFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                 if(file!= null)
                 {

                    Log.d(Tag,"absolute path: "+imageAbsolutePath);
                    Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    i.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(file));        
                    startActivityForResult(i, TAKE_PICTURE);
                 }

And this is the method that returns the file with custom name and location:

private File createImageFile() throws IOException {

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      String currentDate = sdf.format(new Date());

      SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
      String currentTime = sdf2.format(new Date());
      String timeArray[] = currentTime.split(":");

      String imageName = currentDate+" "+timeArray[0]+"-"+timeArray[1]+"-"+timeArray[2];

   // create a File object for the parent directory
   File Pictures = new File(Environment.getExternalStorageDirectory()+File.separator+"Pictures");
   // have the object build the directory structure, if needed.
   if (!Pictures.exists()) {
       Pictures.mkdirs();
       Log.d(Tag,"Pictures folder created: "+Pictures);
       }else
       {
           Log.d(Tag,"Pictures folder Already Exists: "+Pictures);
       }

       // File image = File.createTempFile(imageName,".jpg",Pictures);
   File image = new File (Pictures,imageName+".jpg" );
        Log.d(Tag,"This is Image name: "+ imageName);
        imageAbsolutePath = image.getAbsolutePath();

        return image;

    }

And this is my inActivityResult method that i use:

case TAKE_PICTURE:
             if(resultCode == RESULT_OK)
                {
                 galleryAddPic();
                    Bitmap imgBitmap=null;

                    try
                        {
                        imgBitmap = lessResolution(imageAbsolutePath);                                             

                        }catch (Exception e)                             
                        {
                            e.printStackTrace();
                        }
                        if (imgBitmap!=null)
                        {
                            images.add(imgBitmap);
GridView grid = (GridView) findViewById(R.id.grid_view);
grid.setAdapter(new ImageAdapter(this));
}

All this methods works on devices like: Motorola Xoom, Motorola Droid, Razor, Some Samsung devices but in Samsung Galaxy Ace s5830m (Android 2.3.6) for example does not work. It take the images correctly but when it returns to onActivityResult nothing happens. After some test i found that it do not display anything because the image is saved on DCIM/Camera folder and not on Pictures folder, so what i am doing wrong?.

Was it helpful?

Solution

I had the same issue that in some phone it was working and for others doesn't, I found my solution in this link I hope this help you:

Deleting a gallery image after camera intent photo taken

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top