得到ACTION_SEND意图的Exif数据(TAG_GPS_LATITUDE) [英] Get Exif data from ACTION_SEND intent (TAG_GPS_LATITUDE)
问题描述
好像这个问题上随处可见,但SO的没有的工作。我送从Android相机的意图,我的应用程序(分享我的Android相机拍摄到我的应用程序一个图像)。
It seems like this question is everywhere on SO but nothing is working. I am sending an intent from the Android camera to my app (sharing a image taken with my Android camera to my app).
在我的 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(空,imageUri.getPath());打印出 /外部/图像/媒体/ 5670
出现错误: E / jhead的:无法打开'/外部/图像/媒体/ 5670
然后 Log.v(空,纬度+ STR);
打印出经纬度空
The error appears: E/JHEAD﹕ can't open '/external/images/media/5670'
and then Log.v(null, "lat "+str);
prints out lat null
?
推荐答案
imageUri.getPath()
不返回文件系统路径,因为的在乌里
不是一个文件。弱实现了可在Android SDK中提供的不支持从的InputStream
,这是读 ExifInterface
你就需要消耗的乌里
可靠,使用 ContentResolver的
。
imageUri.getPath()
does not return a filesystem path, because a Uri
is not a file. The weak implementation of ExifInterface
that is supplied in the Android SDK does not support reading in from an InputStream
, which is what you would need to consume that Uri
reliably, using a ContentResolver
.
您可能需要切换到使用其他EXIF库。我使用<一个href=\"https://android.googlesource.com/platform/packages/apps/Mms/+/master/src/com/android/mms/exif/\"相对=nofollow>谷歌的AOSP一个来自于我的CWAC-相机库彩信应用。
You will probably need to switch to using another EXIF library. I am using Google's AOSP one from the Mms app in my CWAC-Camera library.
这篇关于得到ACTION_SEND意图的Exif数据(TAG_GPS_LATITUDE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!