Bboy820602
Bboy820602

Reputation: 151

Disable camera using setCameraDisabled (ComponentName admin, boolean disabled)

i want to disable my camera with my app

i found there is a function setCameraDisabled (ComponentName admin, boolean disabled);

but i don't know how to use it

what is "ComponentName admin" use?

and i also want to know what permission or admin permission to define?

Upvotes: 1

Views: 2633

Answers (1)

Ivan Fazaniuk
Ivan Fazaniuk

Reputation: 1070

1) put device_policies.xml to your res/xml folder:

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-policies>
    <disable-camera />
  </uses-policies>
</device-admin>

2) declare DeviceAdminReceiver in your manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
.....
  <application ... >

 <receiver
            android:name="com.truiton.devicepolicymanager.DevicePolicyAdmin$MyDevicePolicyReceiver"
            android:description="@string/device_admin_description"
            android:label="@string/device_admin"
            android:permission="android.permission.BIND_DEVICE_ADMIN" >
            <meta-data
                android:name="android.app.device_admin"
                android:resource="@xml/device_policies" />

<intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
                <action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" />
                <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
            </intent-filter>

3) for example for a checkbox put:

private CheckBoxPreference DisableCameraCheckbox;
DevicePolicyManager DPM;
ComponentName DeviceAdminSample;
...
DPM.setCameraDisabled(DeviceAdminSample, DisableCameraCheckbox.isChecked());

So now the camera will be disabled.

Upvotes: 3

Related Questions