Skip to content Skip to sidebar Skip to footer

Simple Way To Get Stock Camera Images Location In Android /dcim/?

I have an idea for an app, and to do it i need to be in the folder where the stock camera stores it's pictures. But since most manufactureres name the folder inside DCIM diferently

Solution 1:

One of the solution is to insert photo to MediaStore using ContentResolver (it will create empty JPG file), retrieve its path and delete it from MediaStore (file will be deleted as well).

publicstatic File getPhotoDirPath(ContentResolver cr)
{
    try
    {
        Uri takenPhotoUri=cr.insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues( 1 ) );
        if ( takenPhotoUri == null )
            returnnull;
        String photoFilePath=null;
        Cursor cursor = cr.query( takenPhotoUri, newString[] { MediaColumns.DATA }, null, null, null );
        if ( cursor != null )
        {
            int dataIdx = cursor.getColumnIndex( MediaColumns.DATA );
            if (dataIdx>=0&&cursor.moveToFirst())
                photoFilePath = cursor.getString( dataIdx );
            cursor.close();
        }
        cr.delete( takenPhotoUri, null, null );
        if (photoFilePath!=null)
            returnnew File(photoFilePath).getParentFile();
        returnnull;
    }
    catch (Exception ex)
    {//insert or delete failedreturnnull;
    }
}   

Note that in some cases (the same as when camera apps are not able to save photos) photos may not be inserted successfully eg. SD card is removed (if device cannot emulate external storage), external storage is mounted read-only or some directory in path is write protected etc.

Solution 2:

So i ended up doing it with .exists()

Stringabcd="is it working ?";
          Filepathimg= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
          Filetestimg=newFile (pathimg, "100MEDIA/");
          if (testimg.exists()){abcd = testimg.toString();}
          else {
              Filetestimg2=newFile (pathimg, "100ANDRO/");
              if (testimg2.exists()){abcd = testimg2.toString();}
              else {
                  Filetestimg3=newFile (pathimg, "Camera/");
                  if (testimg3.exists()){abcd = testimg3.toString();}
                  else {
                      Filetestimg4=newFile (pathimg, "100LGDSC/");
                      if (testimg4.exists()){abcd = testimg4.toString();}
                      else {
                          abcd = "It's not working";
                      }
                  }                   
              }
          }

On my G2 with the folder "100LGDSC" it's working.

Solution 3:

you may take Environment.DIRECTORY_PICTURES as the valid directory.

The following will refer to that directory (but it is not guaranteed in all devices):

FilestorageDir= Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES);

Post a Comment for "Simple Way To Get Stock Camera Images Location In Android /dcim/?"