0

I have an Activity that handles image files:

 if (Intent.ACTION_VIEW.equals(action) && type != null && type.startsWith("image/")) {
        Uri imageUri = i.getData();
        try {
            Bitmap image = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

This gets me the image in the bitmap, however I also need to get exif data from it. Saving the image using image.compress removes this data.

If I click View in gmail for example, there is no real path that I can use, so I'm stuck at trying to get the exif data. Is there a way to get a byte[] of the data passed into my activity, or get the exif data from a Bitmap object?

Note:

This:

ExifInterface exifData = new ExifInterface(imageUri.getPath());

Does not cause an exception, however I get null for all the tags, and if I try to print the path, I get this:

/my.email@gmail.com/messages/248/attachments/0.1/BEST/false

If I first hit save and then view in gmail, I can successfully retrieve the exif data with the above method, passing imageUri.getPath() to an exif constructor.

If there is no way to make view work, then how can I make it so the user is prompted to use my application only after saving the file to disk? This is how my intent filters look like right now:

<activity android:name=".GameActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
    </intent-filter>
</activity>
IVlad
  • 43,099
  • 13
  • 111
  • 179

1 Answers1

0

it should be possible to extract the exif data with:

How to use ExifInterface with a stream or URI

Taken from there: http://android-er.blogspot.co.at/2011/04/read-exif-of-jpg-file.html

//Get Real URL
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = parentActivity.managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String realURL = cursor.getString(column_index);

//Access Exif
ExifInterface exifInterface = new ExifInterface(realURL);
String focal_length = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
Community
  • 1
  • 1
aatdark
  • 195
  • 6
  • Wouldn't this only work if the image is downloaded? In my case, I don't think the image is saved to disk. I open it by clicking `View` in gmail before clicking `Download`, which doesn't add it to the gallery database I think?. – IVlad Aug 12 '12 at 21:49
  • how can you view images which have not been downloaded yet? imho every view cmd will download the image and store it in an tmp file. (but this is just a guess) – aatdark Aug 12 '12 at 21:55
  • Just tried it and it causes a crash, I think because that column does not exist. It might download it to a temporary file, but apparently I don't have access to it. `imageUri.getPath()` returns this: `/my.email@gmail.com/messages/248/attachments/0.1/BEST/false`. – IVlad Aug 12 '12 at 22:11