I have a problem with my class, when i call .getMake(); it always returns null, so I get the string "No Data". I know that Uri is not null because i get ther first Toast every time, with the uripath. I also know that the image has the tag "TAG_MAKE" (I checked it). It even didn't work with all the other tags.
What should I change?
public class ExifE { private Uri uri;
private ExifInterface exifI;
private Context context;
public ExifE(Context con) {
context = con;
SharedPreferences prefs = context.getSharedPreferences("prefs", context.MODE_PRIVATE);
uri = Uri.parse(myPrefs.getString("currentImageUri", "fail"));
Toast.makeText(context, uri.getPath(), Toast.LENGTH_SHORT).show();
try {
this.createExifI(uri.getPath());
} catch (IOException e) {
e.printStackTrace();
}
}
public void createExifI(String filePath) throws IOException {
this.exifI = new ExifInterface(filePath);
}
public String getMake() {
String make;
if (exifI.getAttribute(ExifInterface.TAG_MAKE) != null) {
make = exifI.getAttribute(ExifInterface.TAG_MAKE);
} else {
make = "No Data";
}
return make;
}
Solution
There was a problem with creating the ExifInterface.
I can't use uri.getPath();
, I have to call this to get the real filepath not the MediaStore path.
private String getRealPathFromURI(Uri contentURI, Activity activity) {
Cursor cursor = activity.getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file
// path
return contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
}