Toggle the Camera state

Now that you've set up the device admin receiver, activated your license, and configured the required permissions, you can use the APIs to toggle the camera state.

Create the camera policy

This method demonstrates how to use the Knox SDK to toggle the camera state.

 private void toggleCameraState() {

        // Instantiate the EnterpriseDeviceManager class
        EnterpriseDeviceManager enterpriseDeviceManager = EnterpriseDeviceManager.getInstance(this);
        // Get the RestrictionPolicy class where the setCameraState method lives
        RestrictionPolicy restrictionPolicy = enterpriseDeviceManager.getRestrictionPolicy();

        boolean cameraEnabled = restrictionPolicy.isCameraEnabled(false);

        try {
            // Toggle the camera state on/off
            restrictionPolicy.setCameraState(!cameraEnabled); //true
            utils.log(getResources().getString(R.string.camera_state, !cameraEnabled));

        } catch (Exception e) {

Tutorial Progress

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