按下硬键返回按钮时相机崩溃。这会影响相册中的相册和拍照。我尝试通过检查intent action()
是否为空来尝试处理此问题。但它仍然崩溃。非常感谢任何建议。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==0){
if(data.getAction() != null){
Bitmap theImage = (Bitmap)data.getExtras().get("data");
if(theImage !=null){
iv.setImageBitmap(theImage);
}
}
}
else if (requestCode == 1) {
if(data.getAction() != null){
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]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
if(picturePath !=null){
iv.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
}
*** ****更新
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//getInfo is the Bundle
if(data !=null || getInfo !=null){
if(requestCode==0){
if(data.getAction() != null){
Bitmap theImage = (Bitmap)data.getExtras().get("data");
if(theImage !=null || getInfo !=null || data!=null){
iv.setImageBitmap(theImage);
}
}
}
答案 0 :(得分:2)
在null
内加入onActivityResult()
值检查。
在使用之前检查Intent data
是否为空以及是否为hasExtra()
。
即
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data!=null){
// Your code
}
}