How to return an image from my custom camera app called from other app via intent ACTION_IMAGE_CAPTURE
<p>I managed to build a simple but working custom camera application.
So far I can launch it directly and have it taking photos.
I also added proper intent-filters to have it published as an available application to reply to intent calls of another application containing a line of code such as this one: <code>Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);</code></p>

<p>The problem is: <strong>How do I code my camera app to send back images to external apps that pass a URI for saving?</strong></p>

<p>Currently I have a method that detects whether the camera has been launched directly or invoked to reply to an intent-filter: this method is <code>isImageCaptureIntent</code> (working).</p>

<p>I suppose I have to write something in the <code>onPictureTaken</code> method of the <code>PictureCallback</code> but all attempts stop in NullPointerExceptions once I try to write to OutputStrems.</p>

<p>Note that <code>mSaveUri</code> is already filled with the proper URI provided by the calling application from this line of code: <code>mSaveUri = (Uri) myExtras.getParcelable( MediaStore.EXTRA_OUTPUT );</code></p>

<p>Here is the method:</p>

<pre><code> PictureCallback myPictureCallback_JPG = new PictureCallback() {

    @Override
    public void onPictureTaken(final byte[] arg0, Camera arg1) {);

        if (isImageCaptureIntent()) {

            if (mSaveUri != null) {
                OutputStream outputStream = null;
                try {
                    outputStream = getContentResolver()
             .openOutputStream(mSaveUri);  &lt;== HERE I GET NullPointerException
                    outputStream.write(arg0);
                    outputStream.close();
                    setResult(RESULT_OK);
                    finish();
                } catch (IOException ex) {
                    // ignore exception
                } finally {
                }
            } 
        }
        camera.startPreview();
    }
};
</code></pre>
