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: Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
The problem is: How do I code my camera app to send back images to external apps that pass a URI for saving?
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 isImageCaptureIntent
(working).
I suppose I have to write something in the onPictureTaken
method of the PictureCallback
but all attempts stop in NullPointerExceptions once I try to write to OutputStrems.
Note that mSaveUri
is already filled with the proper URI provided by the calling application from this line of code: mSaveUri = (Uri) myExtras.getParcelable( MediaStore.EXTRA_OUTPUT );
Here is the method:
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); <== HERE I GET NullPointerException
outputStream.write(arg0);
outputStream.close();
setResult(RESULT_OK);
finish();
} catch (IOException ex) {
// ignore exception
} finally {
}
}
}
camera.startPreview();
}
};