【问题标题】:Android's camera doesn't go back to my app when photo has been taken拍摄照片后,Android 的相机不会返回我的应用程序
【发布时间】:2011-12-17 22:56:55
【问题描述】:

它甚至无法在 sdcard 上创建文件夹。当相机拍照时,按下“确定”按钮时它没有响应。我的代码有什么问题?

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

【问题讨论】:

    标签: android camera


    【解决方案1】:

    你有这个吗?您需要覆盖 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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多