Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

glenn romaniuk
glenn romaniuk
32,520 Points

android studio - getOutputMediaFileUri - returning null

i'm working on the self destructing message app Ran into a problem with the code that is used to capture an image

The getOutputMediaFileUri always returns null. I've added permissions to the manifest. Why?

                Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
                if (mMediaUri == null){
                    Toast.makeText(MainActivity.this,R.string.error_external_storage, Toast.LENGTH_LONG).show();
                }
                else{
                    takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
                    startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
                }
Daniel Hartin
Daniel Hartin
18,106 Points

Hi Glenn

have you got the code for your getOutputMediaFileUri method? I did a simple google search and stackoverflow led me to this doc page http://developer.android.com/guide/topics/media/camera.html#saving-media

The doc page seems to suggest that this method isn't provided by android and is something the developer must create so I assume another method is at fault than the one posted.

Daniel