我使用以下代码获取图像并将其分配给ImageView。它在Kindle Fire HD(API 15)上运行良好,但在Google Nexus 7上,该设备正在流式传输来自Google的Picassa的照片。如何让毕加萨/流媒体照片工作?
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap pic = BitmapFactory.decodeFile(filePath);
mProfilePic = new BitmapDrawable(getResources(),pic);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
mChangePicImgButton.setBackground(mProfilePic);
else
mChangePicImgButton.setBackgroundDrawable(mProfilePic);
}
}
}
filePath 可能在 null at
Bitmap pic = BitmapFactory.decodeFile(filePath);
您确定设备上存在该文件吗?
编辑:如果您在使用Picasa时遇到问题,这里有一个答案:检索Picasa图像以从图库上传