ACTION_PICK与MediaStore.Images.Media.INTERNAL_CONTENT_URI允许用户通过挑Picasa同步图像(不是设备?) [英] ACTION_PICK with MediaStore.Images.Media.INTERNAL_CONTENT_URI allowing users to pick images synced via picasa (not on device?)
问题描述
我是在平板电脑和手机都运行ICS测试我们的应用程序,并使用相同的谷歌帐户。如果我拍一张照片上的话,会显示在其他设备(通过Picasa中同步)上。奇怪的是,照片显示了在两台设备上,当我做正常
I was testing our app on a tablet and phone both running ICS and using the same Google account. If I take a photo on one it will show up on the other device (syncing via Picasa). The weird thing is that photo shows up on both devices when I do the normal
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
让用户从库中选择一个图像。我的onActivityResult()看起来是这样的:
to let the user pick an image from the gallery. My onActivityResult() looks like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) {
return; // user cancelled
}
Uri imageUri = data.getData();
if (imageUri == null) {
// (code to show error message goes here)
return;
}
// Get image path from media store
String[] filePathColumn = { android.provider.MediaStore.MediaColumns.DATA };
Cursor cursor = this.getContentResolver().query(imageUri, filePathColumn, null, null, null);
if(cursor == null || !cursor.moveToFirst()) {
// (code to show error message goes here)
return;
}
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String imagePath = cursor.getString(columnIndex);
cursor.close();
if (imagePath == null) {
// error happens here
}
}
一切都很好,直到当的ImagePath是空的结束。在code完全适用于其他照片设备,但不是同步一个在。平添几分记录code后看起来这是发生在我们的一些生产中的用户,虽然很少(不到1出10,000张照片)。
Everything is fine until the end when imagePath is null. The code works perfectly for other photos on the device but not the synced one. After adding a bit of logging code it looks like this is happening to some of our users in production, albeit very rarely (less than 1 out of 10,000 photos).
据我所知,ACTION_GET_CONTENT有EXTRA_LOCAL_ONLY标志,只显示本地文件,但这只是在API版本11及以上可用。 ACTION_GET_CONTENT还具有CATEGORY_OPENABLE只显示可以打开的数据。是我ACTION_PICK意图以某种方式(不正确地?),这表明实际上不是本地或可打开的照片?根据该文件,使用INTERNAL_CONTENT_URI只应该显示的照片存储在内部。
I understand that ACTION_GET_CONTENT has the EXTRA_LOCAL_ONLY flag to only show local files, but this is only available on API version 11 and up. ACTION_GET_CONTENT also has CATEGORY_OPENABLE to only show data that can be opened. Is my ACTION_PICK intent somehow (incorrectly?) showing photos that aren't actually local or openable? According to the documentation, using INTERNAL_CONTENT_URI is only supposed show photos stored internally.
还是有我的onActivityResult()code的任何问题?我见过一吨不同的变化:
Or are there any issues with my onActivityResult() code? I've seen a ton of different variations:
- 检查,以确保data.getData()的getPath()不为空
- 使用MediaStore.Images.Media.DATA作为投影,而不是MediaStore.MediaColumns.DATA
- 使用MediaStore.Images.ImageColumns.DATA作为投影,而不是MediaStore.MediaColumns.DATA
- 使用managedQuery()来获得光标,而不是getContentResolver()查询()
- 使用CursorLoader要得到光标(API 11 +)
- 使用getColumnIndexOrThrow()而不是getColumnIndex()
- 调用cursor.getColumnIndex(MediaStore.Images.Media.DATA),然后调用cursor.moveToFirst()
- 使用userImage作为列名(参数getColumnIndex())
是否有任何这些变化的解决这一问题?
Would any of these changes fix the problem?
推荐答案
我有<一个href=\"http://stackoverflow.com/questions/15284592/unable-to-select-particular-images-using-action-pick-intent\">similar这里描述的问题。
我固定它通过使用ContentResolver的直接从意向URI打开一个InputStream:
I fixed it by opening an InputStream directly from the Intent URI using ContentResolver:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == ACTIVITYRESULT_CHOOSEPICTURE) {
final InputStream ist = context.getContentResolver().openInputStream(intent.getData());
final Bitmap bitmap = BitmapFactory.decodeStream(ist);
ist.close();
}
}
这篇关于ACTION_PICK与MediaStore.Images.Media.INTERNAL_CONTENT_URI允许用户通过挑Picasa同步图像(不是设备?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!