Reading and Writing Jpeg Exif Image Details

The ExifInterface class provides mechanisms for you to read and modify the EXIF (Exchangeable Image File Format) data stored within a JPEG file. Create a new ExifInterface instance by passing the full filename in to the constructor.

ExifInterface exif = new ExifInterface(filename);

EXIF data is used to store a wide range of metadata on photographs, including date and time, camera settings (such as make and model), and image settings (such as aperture and shutter speed), as well as image descriptions and locations.

To read an EXIF attribute, call getAttribute on the ExifInterface object, passing in the name of the attribute to read. The Exifinterface class includes a number of static tag_* constants that can be used to access common EXIF metadata. To modify an EXIF attribute, use setAttribute, passing in the name of the attribute to read and the value to set it to.

Listing 11-19 shows how to read the location coordinates and camera model from a file stored on the SD card, before modifying the camera manufacturer details.

^^ LISTING 11-19: Reading and modifying EXIF data Available for downloadon File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");

ExifInterface exif = new ExifInterface(file.getCanonicalPath());

// Read the camera model and location attributes

String model = exif.getAttribute(ExifInterface.TAG_MODEL);


// Set the camera make exif.setAttribute(ExifInterface.TAG_MAKE, "My Phone"); } catch (IOException e) {


By default, media files created by your application will be unavailable to other applications. As a result, it's good practice to insert it into the Media Store to make it available to other applications.

Android provides two alternatives for inserting media into the Media Store, either using the Media Scanner to interpret your file and insert it automatically, or manually inserting a new record in the appropriate Content Provider.

Was this article helpful?

+1 0
Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment