kevalpatel2106 / android-hidden-camera

This library is to take picture using camera without camera preview.
Apache License 2.0
408 stars 155 forks source link

App crashing when calling takePicture() #6

Open passiondroid opened 7 years ago

passiondroid commented 7 years ago
FATAL EXCEPTION: main Process: , PID: 3794
java.lang.RuntimeException: Unable to start service tarun0.gyananter.CaptureService@7a5c685 with Intent { cmp=tarun0.gyananter/.CaptureService }: java.lang.RuntimeException: takePicture failed
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3335)
at android.app.ActivityThread.-wrap21(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1578)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

Caused by: java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1461)
at android.hardware.Camera.takePicture(Camera.java:1406)
at com.androidhiddencamera.CameraPreview.takePictureInternal(CameraPreview.java:181)
at com.androidhiddencamera.HiddenCameraService.takePicture(HiddenCameraService.java:94)
at tarun0.gyananter.CaptureService.onStartCommand(CaptureService.java:63)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3318)
at android.app.ActivityThread.-wrap21(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1578) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6123) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 
kevalpatel2106 commented 7 years ago

@passiondroid Can you please tell me the steps to reproduce the bug?

passiondroid commented 7 years ago

@kevalpatel2106 It started coming today only. Earlier it was not crashing. I am using HiddenCameraService and when takePicture() is called within the service from onStartCommand(). It throws exception with logs

android.hardware.Camera.native_takePicture(Native Method)

kevalpatel2106 commented 7 years ago

@passiondroid On which device you were testing?

passiondroid commented 7 years ago

@kevalpatel2106 Moto G4 plus

kevalpatel2106 commented 7 years ago

Great! Let me check the problem. Meanwhile if you find the issue, you can always generate PR.

passiondroid commented 7 years ago

Ok, I will clone the repo from here as soon as i get some time. I dont know why it stopped working. It was working fine earlier.

kevalpatel2106 commented 7 years ago

Are you using v1.3? or 1.2.1?

passiondroid commented 7 years ago

I am using 1.2.1

kevalpatel2106 commented 7 years ago

Can you test if this issue still occurs in v1.3? I made some changes in v1.3. (See commit: https://github.com/kevalpatel2106/android-hidden-camera/commit/73ce010210641ae5421c924983f2997fecea0723)

passiondroid commented 7 years ago

I am still getting the same exception after changing to 1.3

kevalpatel2106 commented 7 years ago

@passiondroid I made some changes in latest version. Now, HiddenCameraService won't allow you to capture multiple photos simultaneously (like burst mode) because the camera is already acquired while capturing the second image.

Basically, HiddenCameraService won't allow you to take the second picture until the first picture is captured and processed.

kevalpatel2106 commented 7 years ago

Fix in release v1.3.2.

viks178 commented 6 years ago

Maybe the issue is still open Exception java.lang.RuntimeException: takePicture failed android.hardware.Camera.native_takePicture (Camera.java) android.hardware.Camera.takePicture (Camera.java:1473) android.hardware.Camera.takePicture (Camera.java:1418) com.androidhiddencamera.CameraPreview.takePictureInternal (CameraPreview.java:196) com.androidhiddencamera.HiddenCameraService.takePicture (HiddenCameraService.java:95) com.app.mytest.MyCamService$1.run (MyCamService.java:77) android.os.Handler.handleCallback (Handler.java:751) android.os.Handler.dispatchMessage (Handler.java:95) android.os.Looper.loop (Looper.java:154) android.app.ActivityThread.main (ActivityThread.java:6776) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1518) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)

On devices: Samsung SM-A320Y (API 24) Android 7.0 Samsung SM-A510F (API 24) Android 7.0 Samsung SM-G570F (API 24) Android 7.0 Samsung SM-G930A (API 24) Android 7.0 Samsung SM-G930F (API 24) Android 7.0 Samsung SM-G950F (API 24) Android 7.0 Samsung SM-J530FM (API 24) Android 7.0 Samsung SM-J710F (API 24) Android 7.0 Samsung SM-J701F (API 24) Android 7.0 Samsung SM-J700H (API 23) Android 6.0.1 Samsung SM-N920C (API 24) Android 7.0 Xiaomi Redmi Note 4 (API 24) Android 7.0 Motorola Moto G Play (API 23) Android 6.0.1

The application works on these devices, but sometimes this bug appears randomly. The most popular are samsung devices with android 7.0

I found this and this on Stackoverflow. Recommendations are as follows:

Add: SurfaceTexture st = new SurfaceTexture(MODE_PRIVATE); pCamera.setPreviewTexture(st); before: pCamera.startPreview();

sid96 commented 6 years ago

The problem has been in version 1.3.5...This version an be used to take images in burst mode..use that version instead.

androidnoob123 commented 6 years ago

@sid96 can you please show how to take images in burst mode?

gmolina75 commented 4 years ago

Add: SurfaceTexture st = new SurfaceTexture(MODE_PRIVATE); pCamera.setPreviewTexture(st); before: pCamera.startPreview();

works for me on honeywell ED70 , android 7