【发布时间】:2014-11-20 11:06:46
【问题描述】:
我在使用 android 5.0 从图库中挑选图像时遇到问题。我的启动意图代码是:
private void takePictureFromGallery()
{
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(intent, PICK_FROM_FILE);
}
这里是请求代码 PICK_FROM_FILE 的 onActivityResult() 方法中调用的函数
private void handleGalleryResult(Intent data)
{
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
// field declaration private String mTmpGalleryPicturePath;
mTmpGalleryPicturePath = cursor.getString(columnIndex);
cursor.close();
// at this point mTmpGalleryPicturePath is null
...
}
对于 5.0 之前的版本,此代码始终有效,使用 com.android.gallery 应用程序。 Google Photos 是 Android 5.0 上的默认图库应用程序。 这个问题可能取决于应用程序还是新的 android OS 发行版的问题?
编辑
我了解问题所在:Google 相册会自动在云服务器上浏览其备份图像的内容。事实上,如果我关闭每个互联网连接并选择图像后,@maveň 的尝试实践建议,它不会通过从 InputStream 解码位图得到结果。
所以此时问题变成了:在 android 5.0 中有没有办法处理 Intent.ACTION_PICK 动作,以便系统浏览在本地设备图片库中选择?
【问题讨论】:
-
我很抱歉,但还是不明白......你在 onResult() 中调用的 getPath() 方法是用link 编写的方法(在这种情况下,你的参数语法错误) 还是自己写的函数?无论如何,我尝试获取链接中显示的路径,但没有使用 BitmapFactory 解码流,但不起作用。
标签: android photo-gallery