Tutorial - Toggle the Camera state
Now that you have upgraded your Android P.O to a Workspace, you can use the paid Knox APIs to toggle the camera state.
Create the camera policy
This method demonstrates how to use the Knox SDK to toggle the state of the camera.
private void toggleCameraState() {
EnterpriseKnoxManager ekm = EnterpriseKnoxManager.getInstance(this);
KnoxContainerManager kcm = ekm.getKnoxContainerManager(mUtils.findMyContainerId());
RestrictionPolicy restrictionPolicy = kcm.getRestrictionPolicy();
boolean cameraEnabled = restrictionPolicy.isCameraEnabled(false);
try {
// Disable camera. Other applications that use the camera cannot
// use it.
boolean result = restrictionPolicy.setCameraState(!cameraEnabled);
if (result) {
mUtils.log(getResources().getString(R.string.camera_state, !cameraEnabled));
}
} catch (Exception e) {
mUtils.processException(e,TAG);
}
}
Declare the hardware permission in the manifest
You also have to make sure you declare the camera hardware permission in the manifest.
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_HW_CONTROL" />
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_APP_MGMT" />
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_CONTAINER" />
Tutorial progress
You’ve completed 6/7 steps!
NextOn this page
Is this page helpful?