Android: Enable/Disable Camera programmatically

删除回忆录丶 提交于 2019-12-05 08:41:58

问题


I want to enable/disable camera programmatically in my application.


回答1:


You cannot do this from a regular app. You can do it from a device administrator, but the user has to explicitly enable it and it is only available on ICS. Here's the reference: http://developer.android.com/guide/topics/admin/device-admin.html




回答2:


The OP is asking for any ideas, I got one idea and it could possibly work even without using the API provided by ICS.

for lower API version than ICS, you can Start a service that will lock the Camera when the screen is On and Release it when the Screen is Off. This is to minimize the usage of battery.

Since, only one process can use the Camera at a time, other applications like the Camera App will not be able to use the Camera.

The challenge now is how to ensure that the Service Hogging the Camera is always Running and prevent it from being uninstalled by the user.

Well, just a thought ;)




回答3:


Yes, you can use DeviceAdministration class and control the camera source(block and unblock). This is a repo with an example.




回答4:


Yes you can disable or enable camera but your app must device admin enabled.Following enables or disable camera:-

devicePolicyManager.setCameraDisabled(compName, isCameraOn);


**isCameraOn** is boolean true or false


来源:https://stackoverflow.com/questions/10944562/android-enable-disable-camera-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!