How to take a picture without an Intent and without any view window in Android

PGMacDesign

Good day all, I am trying to figure out how to take a picture by pressing a button, without any preview showing up. The idea is, I want a picture to be taken and saved, but no visual preview of the photo before or afterwards. So far, I am able to get the code to take pictures and save them to the disk without any problems, but I cannot seem to do it without a surfaceview or preview.

Here is some of my code:

Main Activity:

public class MainActivity extends Activity implements OnClickListener {

        private Camera cameraObject;
        private ShowCamera showCamera;
        private Button NOPE;

        //Check if camera is avail:
        public static Camera isCameraAvailiable(){
            Camera object = null;
            try {
              object = Camera.open();
                L.m("Camera Open");
            } catch (Exception e) {
              L.m(e.toString());
            } return object; 
        }

       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

          //Opens up the camera
          cameraObject = isCameraAvailiable();

          //Sets the resolution for the camera (Excluded from code here)
          setCameraResolution();

          //Button for taking photos
          NOPE = (Button) findViewById(R.id.button_capture);
          NOPE.setOnClickListener(this);

          //THIS SECTION OF CODE HERE I can't get it to work without it as this creates a view/ preview for the camera
          showCamera = new ShowCamera(this, cameraObject);
          FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
          preview.addView(showCamera);
       }

        public void snapIt(View view){
           cameraObject.takePicture(null, null, new PhotoHandler(getApplicationContext()));
       }

        public void onClick(View view) {
            switch (view.getId()){
            case R.id.button_capture:
                    snapIt(view);
            }
        }   
    }

The photo handler class:

public class PhotoHandler implements PictureCallback {

    private final Context context;

    public PhotoHandler(Context context) {
        this.context = context;
    }

    public void onPictureTaken(byte[] data, Camera camera) {

        File pictureFileDir = getDir();
        if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
            //I removed unnecessary code here, but this is where I write to disk, which works fine.
        }
    }

The problem I am having is that I CANNOT actually take a photo via the camera unless I have the code about preview.addView(showCamera);. The ShowCamera class is merely one that adds a surface view for viewing the pictures while they are being taken:

public class ShowCamera extends SurfaceView implements SurfaceHolder.Callback

Anyone have any ideas? Can this be done?

Someone asked an EXTREMELY similar question here: Taking picture without SurfaceView or without Photo Intent Activity , but without any success. I think I'm on a similar path as they were.

ButterBeast

I have the same problem and I solve it by puting new view over the SurficeView so surficeView was not seen. I spend quite a time by searching for other solution but without success.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to take a picture without an Intent and without any view window in Android

From Dev

Android - Take picture without preview

From Dev

Android : Take a photo from with in my layout without starting a camera intent

From Dev

How to take picture using Intent and send it by email

From Dev

Android SearchView without Intent

From Dev

How to take any number of inputs in python without defining any limit?

From Dev

Api 23 take picture without storage permissions

From Dev

Programmatically Take Picture Without User Interaction

From Dev

take photo and upload it to server without any compress android

From Dev

Taking picture without SurfaceView or without Photo Intent Activity

From Dev

Android - programmatically take a screenshot without having reference to the view / activity

From Dev

Android: take camera picture intent remove confirmation dialog

From Dev

Take picture only with android camera intent in Kotlin, not video

From Dev

Android Tablet Take Picture Camera Intent Activity Restarts

From Dev

Can we use takePicture() in android without camera preview? I need to take a picture secretly for security purposes

From Dev

How to make view not to take any space but still be visible in Android RecyclerView?

From Dev

How to take screen shot of whole desktop without background/wallpaper picture in Windows

From Dev

Android Lazy loading of images with Grid view ( Without using any libraries )

From Dev

Take screenshot from window content (without border)

From Dev

How to Implement Swipe In Android Game Without View

From Dev

How to open another view on button click without creating a Window in Titanium?

From Dev

How to view text file in Firefox window without downloading it?

From Dev

How to open another view on button click without creating a Window in Titanium?

From Dev

How can I change an image view in swift without any animations?

From Dev

How to load view in phalcon without any other contents

From Dev

How to change view automatically without any action in ionic?

From Dev

Take a snapshot of view without adding it to the screen

From Dev

How to take Data from Intent in Android

From Dev

Android picture compression without loading fully into memory

Related Related

  1. 1

    How to take a picture without an Intent and without any view window in Android

  2. 2

    Android - Take picture without preview

  3. 3

    Android : Take a photo from with in my layout without starting a camera intent

  4. 4

    How to take picture using Intent and send it by email

  5. 5

    Android SearchView without Intent

  6. 6

    How to take any number of inputs in python without defining any limit?

  7. 7

    Api 23 take picture without storage permissions

  8. 8

    Programmatically Take Picture Without User Interaction

  9. 9

    take photo and upload it to server without any compress android

  10. 10

    Taking picture without SurfaceView or without Photo Intent Activity

  11. 11

    Android - programmatically take a screenshot without having reference to the view / activity

  12. 12

    Android: take camera picture intent remove confirmation dialog

  13. 13

    Take picture only with android camera intent in Kotlin, not video

  14. 14

    Android Tablet Take Picture Camera Intent Activity Restarts

  15. 15

    Can we use takePicture() in android without camera preview? I need to take a picture secretly for security purposes

  16. 16

    How to make view not to take any space but still be visible in Android RecyclerView?

  17. 17

    How to take screen shot of whole desktop without background/wallpaper picture in Windows

  18. 18

    Android Lazy loading of images with Grid view ( Without using any libraries )

  19. 19

    Take screenshot from window content (without border)

  20. 20

    How to Implement Swipe In Android Game Without View

  21. 21

    How to open another view on button click without creating a Window in Titanium?

  22. 22

    How to view text file in Firefox window without downloading it?

  23. 23

    How to open another view on button click without creating a Window in Titanium?

  24. 24

    How can I change an image view in swift without any animations?

  25. 25

    How to load view in phalcon without any other contents

  26. 26

    How to change view automatically without any action in ionic?

  27. 27

    Take a snapshot of view without adding it to the screen

  28. 28

    How to take Data from Intent in Android

  29. 29

    Android picture compression without loading fully into memory

HotTag

Archive