ExifInterface返回null所有标签 [英] ExifInterface returns null for all Tags

查看:221
本文介绍了ExifInterface返回null所有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的同班同学一个问题,当我叫.getMake();它总是返回null,所以我得到的字符串无数据。我知道,开放的我们不为空,因为我每次都获得第一疗法吐司,与uripath。我也知道,像有标签TAG_MAKE(我检查)。它甚至没有与其他所有标签的​​工作。

我应该怎么改?

 公共类ExifE {私人开放的URI;
私人ExifInterface exifI;
私人上下文的背景下;公共ExifE(上下文CON){
    上下文= CON;
    共享preferences preFS = context.getShared preferences(preFS,context.MODE_PRIVATE);
    URI = Uri.parse(我的prefs.getString(currentImageUri,失败));
    Toast.makeText(上下文,uri.getPath(),Toast.LENGTH_SHORT).show();
    尝试{
        this.createExifI(uri.getPath());
    }赶上(IOException异常五){
        e.printStackTrace();
    }
}公共无效createExifI(字符串文件路径)抛出IOException
    this.exifI =新ExifInterface(文件路径);
}公共字符串getMake(){
    串化妆;
    如果(exifI.getAttribute(ExifInterface.TAG_MAKE)!= NULL){
        使= exifI.getAttribute(ExifInterface.TAG_MAKE);
    }其他{
        令=没有数据;
    }
    返回化妆;
}


解决方案

有是与创建ExifInterface的问题。
我不能使用 uri.getPath(); ,我必须把这种才能获得真正的文件路径不是MediaStore路径

 私人字符串getRealPathFromURI(URI contentURI,活动活动){
    。光标光标= activity.getContentResolver()查询(contentURI,NULL,NULL,NULL,NULL);
    如果(光标== NULL){//来源是Dropbox的或其他类似的本地文件
                            //路径
        返回contentURI.getPath();
    }其他{
        cursor.moveToFirst();
        INT IDX = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        返回cursor.getString(IDX);
    }
}


解决方案

为了使您的当前状态一目了然:你说,你得到无数据 getMake()方法。从而;你是不是从 createExifI得到任何例外 方法。因为如果一个例外已发生,你的 exifI 实例将是 NULL 键,你会得到一个 NPE getMake()方法,但你没有。

如果上面的部分是正确的,那么你的问题的唯一原因是,有不符合标签的任何属性 ExifInterface.TAG_MAKE ExifInterface 实例。你可以试着列出(记录/打印)为所有其他属性 ExifInterface 实例,以确保其他属性存在,但TAG_MAKE。

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

解决方案

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.

这篇关于ExifInterface返回null所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆