【问题标题】:Get Exif data from ACTION_SEND intent (TAG_GPS_LATITUDE)从 ACTION_SEND 意图 (TAG_GPS_LATITUDE) 获取 Exif 数据
【发布时间】:2023-03-10 00:00:01
【问题描述】:

似乎这个问题在 SO 上无处不在,但 什么都没有 在起作用。我正在从 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?

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 2019-03-22
      • 1970-01-01
      • 2018-10-03
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多