0

I am using camera intent to take a picture in a Service by using following code

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
 try {
      getApplication().startActivity(intent);
  } catch (final ActivityNotFoundException e) {
    e.printStackTrace();
  } catch (final Exception e) {
    e.printStackTrace();
  }

It can take the picture; however, every time it shows the preview GUI (having captured picture, Save and Discard buttons). I want to ignore the step, just likes the default capture camera (capture and saving without preview). How could I modify the code? Thank all

Note that: I do not want to use camera2API to make a new app. I want to use the default camera app. Someone said that

"The camera app doesn't give other apps the option to disable the confirmation screen, even though the camera app itself doesn't show the confirmation screen.

Therefore it is not possible for not showing the confirmation screen."

It looks bad new in the past. I am using Android 5.0. Is it possible now?

Jame
  • 3,746
  • 6
  • 52
  • 101
  • refer http://stackoverflow.com/questions/16297606/android-take-camera-picture-without-save-delete-confirmation – Jitesh Mohite Nov 29 '16 at 06:29
  • No. I do not want to use camera2API – Jame Nov 29 '16 at 06:29
  • it is not possible. And shouldn't be possible since nobody wants an app without camera permission to take photos in background. – Vladyslav Matviienko Nov 29 '16 at 07:28
  • How about automatically accepted the process? It means its default is save option – Jame Nov 29 '16 at 07:30
  • `since nobody wants an app without camera permission to take photos in background`. You mean: `since nobody wants an app with camera permission to take photos in background`. @Vlad Matvienko – greenapps Nov 29 '16 at 09:38
  • @all: I solved it by add the action intent.setAction("android.media.action.STILL_IMAGE_CAMERA"); It worked in my case. You can test in your phone – Jame Nov 29 '16 at 10:14

2 Answers2

2

I found a good solution using adb shell

adb shell "am start -a android.media.action.STILL_IMAGE_CAMERA" && sleep 1 && adb shell "input keyevent 27"

Notice the action is STILL_IMAGE_CAMERA

Reference Android 4.4 won't allow me to save a picture when captured using adb commands

Community
  • 1
  • 1
Jame
  • 3,746
  • 6
  • 52
  • 101
1

It is impossible.

You cannot control the behavior of the default camera app. Worse than that, you do not know what app will be used to fulfill your ACTION_IMAGE_CAPTURE intent. The end user has full power to install an alternative camera app, or may have malware installed that pretends to be a camera app (being a camera app means in this context that the manifest declares that it can perform ACTION_IMAGE_CAPTURE). But first of all, the ODMs preinstall camera apps that not necessarily behave the same way as the AOSP camera.

Such app may follow the contract for ACTION_IMAGE_CAPTURE intent response, but there is no guarantee. SO is full of questions about situations where the preinstalled camera app does not recognize extras correctly, or produces unexpected results.

Even if the result looks correct, there is no way for your app to know if the picture is actually being taken by the camera. It could be an image from the gallery, or a fake image, if the camera app chooses so.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Thank Alex Cohn, for control the taking picture, I was successful by using command line `su", "-c","input keyevent "+KeyEvent.KEYCODE_CAMERA`. Do you know any keyevent to auto saving the image? I am running in a root device (ADB Shell) – Jame Nov 29 '16 at 07:41
  • I found the solution by adding the Action `intent.setAction("android.media.action.STILL_IMAGE_CAMERA");` It worked well in my S5 phone. I am not sure about other phone. – Jame Nov 29 '16 at 07:51