Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android's camera doesn't go back to my app when photo has been taken

Tags:

android

camera

It even can't make a folder on the sdcard. When the camera takes the photo, it doesn't respond when I press the 'OK' Button. What's wrong with my code?

public static final String MACCHA_PATH = Environment.getExternalStorageDirectory().getPath() + "/Twigit";
public static final String PHOTO_PATH = MACCHA_PATH + "/camera.jpg";

public static boolean takePhoto(Activity activity) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File fileDir = new File(MACCHA_PATH);
    boolean isSuccessful = true;
    if (!fileDir.exists()) {
        isSuccessful = fileDir.mkdir();
    }
    if(!isSuccessful) {
        return false;
    } else {
        File file = new File(PHOTO_PATH);
        Uri outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        activity.startActivityForResult(intent, TAKEPHOTO);
        return true;
    }
}
like image 425
Twigit--赵汝鹏 Avatar asked Nov 05 '22 09:11

Twigit--赵汝鹏


1 Answers

do you have this? You need to override the onActivityResult. which will be called before onResume when you use startActivityForResult. The requestCode will be the code you used to start the photo taking activity. In your case it would be TAKEPHOTO..

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKEPHOTO) {
        if (resultCode == RESULT_OK) {
            //Pic taken
        } else {
            //Pic not taken
        }
    } 
}

EDIT: take a look at this link http://achorniy.wordpress.com/2010/04/26/howto-launch-android-camera-using-intents/

like image 113
Rejinderi Avatar answered Nov 11 '22 11:11

Rejinderi