5

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;
    }
}
Bart
  • 19,692
  • 7
  • 68
  • 77

1 Answers1

2

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/

Rejinderi
  • 11,694
  • 2
  • 31
  • 40