这是我在我的应用程序中用于打开图库和相机的代码。在没有设置的情况下按下后退按钮时应用程序崩溃 图片。建议我解决它。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0 && resultCode == RESULT_OK) {
if (data != null) {
// this is image view where you want to setimage
bmp = (Bitmap) data.getExtras().get("data");
ivKidsProfilePicture.setImageBitmap(bmp);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, baos);
childpic = baos.toByteArray();
Log.d("camera ---- > ", "" + data.getExtras().get("data"));
}
masterDatabaseAdapter.insertProfilePicture(childpic);
}
else {
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 filePath = cursor.getString(columnIndex);
cursor.close();
if (bmp != null && !bmp.isRecycled()) {
bmp = null;
}
bmp = BitmapFactory.decodeFile(filePath);
ivKidsProfilePicture.setBackgroundResource(0);
ivKidsProfilePicture.setImageBitmap(bmp);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, baos);
childpic = baos.toByteArray();
}
masterDatabaseAdapter.insertProfilePicture(childpic);
}