从ACTION_SEND intent获取Exif数据(TAG_GPS_LATITUDE)

时间:2015-04-08 11:46:09

标签: android android-intent

似乎这个问题无处不在,但没有什么正在运作。我正在从Android相机向我的应用发送一个意图(将我的Android相机拍摄的图像分享到我的应用)。

framgent

// ...
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = null;

    Intent intent = getActivity().getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
        // ...
        } else if (type.startsWith("image/")) {
            Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            if (imageUri != null) {
                Log.v(null, imageUri.getPath());
                try {
                    ExifInterface exif = new ExifInterface(imageUri.getPath());
                    String str = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
                    Log.v(null, "lat "+str);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                // ...
            }
        }
    } else {
        view = inflater.inflate(R.layout.fragment_main, container, false);
        initComponents(view);
        initListeners();
    }
    return view;
}
// ...

Log.v(null,imageUri.getPath());打印出/external/images/media/5670

出现错误:E/JHEAD﹕ can't open '/external/images/media/5670'然后Log.v(null, "lat "+str);打印出lat null

1 个答案:

答案 0 :(得分:0)

imageUri.getPath()未返回文件系统路径,因为a Uri is not a file。 Android SDK中提供的ExifInterface的弱实现不支持从InputStream读入,这是您需要使用{{1}可靠地使用Uri }}

您可能需要切换到使用其他EXIF库。我在CWAC-Camera库中使用Google's AOSP one from the Mms app