我使用了OnActivity Result代码,其中使用了switch语句,但是在case 2
中遇到了错误
switch (requestCode) {
case (1):
//Code for camera
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
break;
case (2):
//Code for Gallery
if (resultCode == RESULT_OK) {
Uri photoUri = data.getData();
if (photoUri != null) {
try {
currentImage = MediaStore.Images.Media.getBitmap(
this.getContentResolver(), photoUri);
selectedImage.setImageBitmap(currentImage);
} catch (Exception e) {
e.printStackTrace();
}
}
}
break;
}
//imageView.setImageBitmap(photo);
}
答案 0 :(得分:2)
如果没有case
,
switch (requestCode) {
case (1):
//Code for camera
if (requestCode == Activity.CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
}
break;
case (2):
if (resultCode == Activity.RESULT_OK) {
Uri photoUri = data.getData();
if (photoUri != null) {
try {
currentImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), photoUri);
selectedImage.setImageBitmap(currentImage);
} catch (Exception e) {
e.printStackTrace();
}
}
}
break;
}