0

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();
    }
};
keyser
  • 18,829
  • 16
  • 59
  • 101
mcfoi
  • 74
  • 7

2 Answers2

0

there are similar questions to this one. one post says it's a problem on htc devices. here:

in any case , i would suggest sending a request to capture an image , and receiving the path to it , and use MODE_WORLD_READABLE for the file , or use an external storage path .

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
0
       mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, opt);

        Matrix mtrxFreeze = new Matrix();
        mtrxFreeze.postRotate(90);

        mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(),
                mBitmap.getHeight(), mtrxFreeze, true);