Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera doesn't be released sometimes after application re-installed

Tags:

android

camera

I'm developing a camera application. Sometimes I tried to re-install the app when it is in foreground. In the installation process, the application will be killed, and the the onPause() won't be invoked, in which I stop the preview and release the camera resource. Under normal circumstances, the system will automatically close and release the camera, and I got the following log.

03-14 15:48:36.316: E/CameraHardwareSec(83): Could not dequeue gralloc buffer!
03-14 15:48:36.316: I/CameraHardwareSec(83): int android::CameraHardwareSec::previewThreadWrapper(): calling mSecCamera->stopPreview() and waiting
03-14 15:48:36.363: I/CameraHardwareSec(83): int android::CameraHardwareSec::previewThreadWrapper(): return from wait
03-14 15:48:36.363: I/CameraHardwareSec(83): int android::CameraHardwareSec::previewThreadWrapper(): exiting
03-14 15:48:36.363: W/SecCamera(83): int android::SecCamera::stopPreview(): doing nothing because m_flag_camera_start is zero
03-14 15:48:36.363: W/SecCamera(83): int android::SecCamera::stopRecord(): doing nothing because m_flag_record_start is zero
03-14 15:48:36.363: I/SecCamera(83): DeinitCamera: m_cam_fd(29)
03-14 15:48:36.371: I/SecCamera(83): DeinitCamera: m_cam_fd2(30)
03-14 15:48:36.386: E/CameraHardwareSec(83): preview window is NULL!
03-14 15:48:36.386: I/CameraService(83): Destroying camera 0
03-14 15:48:36.386: I/CameraHardwareSec(83): int android::HAL_camera_device_close(hw_device_t*)
03-14 15:48:36.386: I/SecCamera(83): DeinitCamera : already deinitialized
03-14 15:48:36.390: W/AudioFlinger(83): session id 89 not found for pid 83
03-14 15:48:36.394: W/AudioFlinger(83): session id 90 not found for pid 83

However sometimes these log information didn't print out. And I guess it means the camera was not released. So when the app restarted, it throws a runtime exception "failed to connect to camera service" when trying open the camera.

Does anyone have any idea about why the system didn't release the camera when killed it.

like image 284
Star Chu Avatar asked Mar 13 '26 23:03

Star Chu


1 Answers

Did you add permissions to your Manifest file?

<uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />
like image 200
Natali Avatar answered Mar 16 '26 13:03

Natali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!