我的应用中有一些代码可以很好地打开画廊(从我的应用中),选择一张照片,然后上传它。
我已经做出了公平的尝试来集成对附加了 EXTRA_STREAM 的意图的处理,例如由图库中的“共享”按钮生成的那些。
这适用于我的 Droid X,也适用于模拟器。
今天,我收到一个用户的错误报告;当我要求它返回 EXTRA_STREAM 参数中引用的资源时,我用来从 MediaStore 中拉出照片的光标返回 null。代码已经通过了验证 Intent 附加了 EXTRA_STREAM 的点,用户告诉我他们正在使用图库中的“共享”选项。
他们的设备是:
操作系统版本:2.3.3(10 / GRI40) 设备:HTC PG86100
是什么赋予了?
为什么 HTC 图库会向我发送带有我无法访问的 EXTRA_STREAM 的 Intent?
游标返回 null 还有其他原因吗?
String[] filePathColumn = {MediaColumns.DATA};
Uri selectedImageUri;
//Selected image returned from another activity
if(fromData){
selectedImageUri = imageReturnedIntent.getData();
} else {
//Selected image returned from SEND intent
// This is the case that I'm having a problem with.
// fromData is set in the code that calls this;
// false if we've been called from an Intent that has an
// EXTRA_STREAM
selectedImageUri = (Uri)getIntent().getExtras().get(Intent.EXTRA_STREAM);
}
Cursor cursor = getContentResolver().query(selectedImageUri, filePathColumn, null, null, null);
cursor.moveToFirst(); // <-- NPE on this line