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 (Undefined variable: Variables.KnoxSDK) 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) {

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="" />
<uses-permission android:name="" />  
<uses-permission android:name="" />

Tutorial Progress

You are 6/7 done! Go to the next step.