Release Android Camera without restart?

user766650 picture user766650 · Nov 15, 2011 · Viewed 15.6k times · Source

I'm currently trying to get the camera working in my app and I'm having issues with the whole camera.release() thing; I'm doing pretty complicated stuff and there's no clear cut way to simply call camera.release() so I have to keep trying new ways, but every time I get it wrong my app crashes (as expected), leaving the camera not released. So, in order to be able to test my app again, I need to restart my phone in order to refresh the camera.

Is there any way to release the camera through the terminal or DDMS, or is the only way to release it by restarting my phone? It's getting pretty old, especially when a tiny mistake leads to wasted time waiting for my phone to restart.

Thanks!

Answer

Vanuan picture Vanuan · Nov 11, 2013

Camera resource management is done by the android Camera Service (libcameraservice.so). The process that runs Camera Service is mediaserver. If you restart the Media Server, you'll effectively release all camera locks.

You must have adb root access to do that.

Run adb shell; su to get root command prompt.

root@m0:/ # ps|grep media
media     1901  1     129268 6168  ffffffff 4026d470 S /system/bin/mediaserver
media_rw  1909  1     3064   1380  ffffffff 4015f1ac S /system/bin/sdcard
u0_a19    22821 1899  484316 21588 ffffffff 4016d574 S android.process.media
root@m0:/ # kill 1901
kill 1901

Media server should be started automatically now.

Android 7.0

The lastest version of Android has the mediaserver binary split into multiple dedicated binaries to help with security. Read more in the official documentation.

So instead of the mediaserver you should look for the cameraserver. Not tested though.