拍摄照片后,Android的相机不会返回我的应用程序

时间:2011-12-17 14:40:55

标签: android camera

它甚至无法在SD卡上创建文件夹。当相机拍摄照片时,按下“确定”按钮时它不会响应。我的代码出了什么问题?

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;
    }
}

1 个答案:

答案 0 :(得分:2)

你有这个吗?您需要覆盖onActivityResult。当你使用startActivityForResult时,将在onResume之前调用它。 requestCode将是您用于开始拍照活动的代码。在你的情况下,它将是TAKEPHOTO ..

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

编辑: 看看这个链接 http://achorniy.wordpress.com/2010/04/26/howto-launch-android-camera-using-intents/