ExifInterface returns null for all Tags

余生长醉 提交于 2019-12-25 02:25:10

问题


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);
    }
}

回答1:


To make your current status clear: You said that you get "No Data" response from getMake() method. Thus; you are not getting any Exception from createExifI method. Because if an Exception was occured, your exifI instance was going to be NULL and you were going to get a NPE from getMake() method but you didn't.

If above part is correct, then the only reason for your problem is that there aren't any attributes with tag ExifInterface.TAG_MAKE for that ExifInterface instance. You may try to list(log/print) all other attributes for that ExifInterface instance to be sure that other attributes exist but TAG_MAKE.



来源:https://stackoverflow.com/questions/19960790/exifinterface-returns-null-for-all-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!