Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Self-Destructing Message Android App Capturing Photos and Videos Setting Where Photos are Saved

Mahmoud Tokura
Mahmoud Tokura
789 Points

Cant find File Path

Im using genymotion as my emulator, when i run my app i get this "File: file:///storage/emulated/0/Pictures/Ribbit/IMG_20150509_1202.jpg in log"

but i can find this file path i my emulator file manger.

see my code below.

private Uri getOutPutMediaFileUri(int mediaType) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. if(isExtenalStorageAvailable()){ //Get Uri;

            //1. get the external storage directory
            String appName = MainActivity.this.getString(R.string.app_name);

            File mediaStorageDir = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),appName);

            //2. Create our subdirectory
            if(! mediaStorageDir.exists()){
               if(! mediaStorageDir.mkdirs()){
                   Log.e(TAG, "Failed to create directory.");
                   return null;
               }
            }
            //3. Create a file name

            //4. Create the file
            File mediaFile;
            Date now = new Date();
            String timestamp = new SimpleDateFormat("yyyyMMdd_HHss",Locale.US).format(now);

            String path=mediaStorageDir.getPath() + File.separator;
            if(mediaType == MEDIA_TYPE_IMAGE){
                mediaFile = new File(path + "IMG_" + timestamp + ".jpg");
            }else if(mediaType == MEDIA_TYPE_VIDEO){
                mediaFile = new File(path + "VID_" + timestamp + ".mp4");
            }else {
                return null;

            }
            Log.d(TAG,"File: " + Uri.fromFile(mediaFile));

            //5. Return the files Uri
            return Uri.fromFile(mediaFile);
        }

        else {

            return null;
        }
    }
Mahmoud Tokura
Mahmoud Tokura
789 Points

Found the solution, was a bit annoying but at least i works.

Daniel Vido
Daniel Vido
4,824 Points

Hi, What was the solution? :) I have the same issue.