Matthias Schippling Matthias Schippling - 2 months ago 27
Android Question

How to use Intent(MediaStore.ACTION_IMAGE_CAPTURE) and get GPS data in the picture?

Is there a way to get a photo taken with Intent(MediaStore.ACTION_IMAGE_CAPTURE) and the stock camera app, which has the GPS location already set in the Exif data?

My app requests

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

in the Manifest and also

ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION)
ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)

in the code, but the photo I receive doesn't contain the location data. When I take a picture directly with the camera the location information is available in the photo.

EDIT: I forgot to add that I'm using a Nexus 6P to test it and when I use the included Camera app (3.2.045) for the ACTION_IMAGE_CAPTURE intent I see the "location pin" in the system tray for a second before the camera viewfinder is shown. This led me to believe that there might be a setting or parameter missing that would enable the writing of location information in the picture file.


First, there is no single "stock camera app". There are thousands of Android device models. They will ship with hundreds of different "stock camera app" implementations, as most device manufacturers create their own (and, in the case of Samsung, have many such camera apps across their fleet). Plus ACTION_IMAGE_CAPTURE will not necessarily use a "stock camera app". Rather it uses whatever the user wants to, which may be a third-party camera app installed from the Play Store or elsewhere.

There is no way for your app to request EXIF location data be added to the photo by the camera app, and there is no requirement for a camera app to include EXIF location data. I am not the least bit surprised at the results you are seeing.

You are welcome to get the location data yourself and, using an EXIF library, add that data to the photo, if needed.