0

I am using Android 5.0 to implement an application which allows to automatically capture and save an image into my phone. Currently, I am using bellow code but it requires press the capture button in Capture UI of my phone. Is it possible to capture and save the image without press the capture button? For example, I just call the function myCaptureandSave(), then the phone will display Capture UI and intermediately capture the image and save, I do not need doing more step.

        public void myCaptureandSave() {
        String image_path = Environment.getExternalStorageDirectory() +"/"+System.currentTimeMillis()+".jpg";
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        //File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        File output = new File(image_path);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
        }
Jame
  • 3,746
  • 6
  • 52
  • 101
  • 1
    You can't do that with an intent. The intent opens up other apps. You have to make your own camera app. Folow [this](https://developer.android.com/guide/topics/media/camera.html#custom-camera) for instructions – Drilon Blakqori Aug 19 '16 at 13:34

3 Answers3

1

You have to use Camera Api. Create Service, running in background, which hold reference to this api and current SurfaceTexture, it is necessary, camera will be 'previewing to nowhere'. after that you'll be able to take pictures even if device is locaked

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11
1

Yes it is possible, but I believe you can't do it using the internal camera (calling the intent). You have to use Camera2 API.

I made a library to use Camera2 API, you can take a look at it if you want:

https://github.com/omaflak/Android-Camera2-Library

In your case, simply pass a dummy SurfaceTexture for the preview and call takePicture().

Hope it will help

Omar Aflak
  • 2,918
  • 21
  • 39
0

how to capture an image in background without using the camera application

i tried with this time ago and with little bit changes i got it. Hope this helps..

Community
  • 1
  • 1
Nikhil Borad
  • 2,065
  • 16
  • 20