我的Android应用程序在案例2崩溃,案例3不起作用(不要从相机拍照)。案例0和案例1运作良好。
onClick方法:
public void onClick(View v) {
if(position == 0 && menuID == mFrameID1)
{
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 1);//pick photo from gallery
}
else if(position == 1 && menuID == mFrameID1)
{
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);//capture from camera
}
else if(position == 0 && menuID == mFrameID2)
{
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 2);//pick photo from gallery
}
else if(position == 1 && menuID == mFrameID2)
{
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 3);//capture from camera
}
}
onActivityResult方法
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
mPhotoConteiner2.setImageBitmap(photo);
}
break;
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
mPhotoConteiner2.setImageURI(selectedImage);
}
break;
case 2:
if(resultCode == RESULT_OK){
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
mPhotoConteiner1.setImageBitmap(photo);
}
break;
case 3:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
mPhotoConteiner1.setImageURI(selectedImage);
}
break;
}
}
它崩溃了
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
案例2
对不起那个问题,我是android编程的新手。 并寻求帮助。
答案 0 :(得分:0)
哦,问题在于,当我在错误的地方编写案例2和案例3的代码时。我应该在case3中编写case2代码,在case2中编写case3。