Disable camera using setCameraDisabled (ComponentName admin, boolean disabled)

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.

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *