保存后,相机活动不会返回结果

时间:2011-12-24 10:51:17

标签: android android-camera-intent

我有一个代码用于拍摄照片并在之前在地图上显示。即使我没有改变与该部分相关的代码,它在安装android 2.3.6后也无法正常工作。我调试了代码,代码没有进入onActivityResult方法。我现在无法在其他版本中调试该软件。任何人都可以帮我解决这个问题。相关代码如下:

    protected void startCameraActivity() {
File fileDirectory = new File(Environment.getExternalStorageDirectory()+ filePath);
        // have the object build the directory structure, if needed.
        fileDirectory.mkdirs();
        imageNumber++;
        File file = new File(fileDirectory, "image_" + imageNumber
                + ".jpg");
        if (file.exists()) file.delete();
        Uri outputFileUri = Uri.fromFile(file);
        imagePath = file.toString();
        Intent intent = new Intent(
                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

        startActivityForResult(intent, 0);
}
@Override   
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (resultCode) {
    case -1:
        // this code performs operations about the saved image file
        new LongOperation().execute("");
        break;
    }
    switch (requestCode) {
    case 3:
    enableGPS();    
    break;
    }
}

2 个答案:

答案 0 :(得分:2)

onActivityResult()

中添加此行
    super.onActivityResult(requestCode, resultCode, data);

答案 1 :(得分:0)

经过一番研究后,我找到了一个解决方案:The problem with an external camera in Android using MediaStore.ACTION_IMAGE_CAPTURE