My android app is crashing in case 2 and case 3 don't work(don't take picture from camera). Case 0 and Case 1 works well.
onClick method:
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 method
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;
}
}
Its crashing at line
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
in case 2
Sorry for that kind question, im newbie to android programming. And thx for help.
Oh, the problem was that when I'm wrote code for case 2 and case 3 in wrong places. I should write case2 code in case3 and case3 in case2.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.