Camera Result always returns RESULT_CANCELED : <p>I want to take pictures with my camera. I just need them temporally so i do the following:</p>

<pre><code>private void takePicture() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    if (intent.resolveActivity(this.getActivity().getPackageManager()) != null) {
        try {
            this.imageFile = File.createTempFile("CROP_SHOT", ".jpg", this.getActivity().getCacheDir());

            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(this.imageFile));
            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

            this.startActivityForResult(intent, Globals.REQUEST_TAKE_PHOTO);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
</code></pre>

<p>Unfortunately the result code <code>RESULT_CANCELED</code> in my <code>onActivityResult</code></p>

<pre><code>@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.v("PictureEdit", "onActivityResult");

    super.onActivityResult(requestCode, resultCode, data);

    if(resultCode == Activity.RESULT_OK) {
        if(requestCode == Globals.REQUEST_TAKE_PHOTO) {
            Log.v("PictureEdit", "onActivityResult take photo");

            this.startCropImage(Uri.fromFile(this.imageFile));
        } else if (requestCode == Globals.REQUEST_PICK_PHOTO) {
            Log.v("PictureEdit", "onActivityResult pick photo");

            this.startCropImage(data.getData());
        } else if (requestCode == Globals.REQUEST_CROP_PHOTO) {
            Log.v("PictureEdit", "onActivityResult crop photo");

            this.imageEncoded = data.getStringExtra(Globals.KEY_IMAGE_ENCODED);

            this.imageView.setImageBitmap(Images.decodeImage(imageEncoded));
            this.buttonSave.setEnabled(true);
        } else {
            Log.v("PictureEdit", "onActivityResult requestCode: " + requestCode + ", result: " + resultCode);
        }
    } else {
        Log.v("PictureEdit", "onActivityResult resultCode is not ok: " + resultCode);
    }
}
</code></pre>

<p>Every solutions i found so far on stackoverflow and in the web did not solve my problem. I use the cache directory for creating a temp file:</p>

<pre><code>File.createTempFile("CROP_SHOT", ".jpg", this.getActivity().getCacheDir());
</code></pre>

<p>And i have the correct permissions:</p>

<pre><code>&lt;uses-permission android:name="android.permission.CAMERA" /&gt;
&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
&lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
&lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
</code></pre>

<p>Picking images from my smartphone always works fine:</p>

<pre><code>private void pickPicture() {
    Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    this.startActivityForResult(intent, Globals.REQUEST_PICK_PHOTO);
}
</code></pre>

<p>So why is the camera always returning <code>RESULT_CANCELED</code>? </p>

<p>It is appearing on Nexus 4 with Android 6.0 and on Samsung Galaxy S III with Android 4.2.</p>
