Android: Enable/Disable Camera programmatically

2020-06-26 23:33发布

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

4条回答
beautiful°
2楼-- · 2020-06-26 23:59

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
查看更多
我命由我不由天
3楼-- · 2020-06-27 00:02

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 ;)

查看更多
Animai°情兽
4楼-- · 2020-06-27 00:04

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

查看更多
老娘就宠你
5楼-- · 2020-06-27 00:05

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

查看更多
登录 后发表回答