Menu

Turn on ProKiosk Mode

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

Enable ProKiosk Mode

This method demonstrates how to enter ProKiosk Mode. Paste the following code in MainActivity()

private void enterProKioskMode() {
        try {
            String defaultPassCode = "12345";
            ProKioskManager proKioskManager = CustomDeviceManager.getInstance().getProKioskManager(); 
	// Instantiate the ProKioskManager class where the setProKioskState method lives

            proKioskManager.setHomeActivity(getPackageName()); 
	// Set the home activity of ProKiosk Mode to this app
            int result = proKioskManager.setProKioskState(true, defaultPassCode); 
	// Enable ProKiosk Mode and get the result code
            if (result == CustomDeviceManager.SUCCESS) {
                mUtils.log(getString(R.string.entered_prokiosk));
            } else if (result == CustomDeviceManager.ERROR_INVALID_PASSCODE) {
                mUtils.log(getString(R.string.error_passcode));
            } else if (result == CustomDeviceManager.ERROR_PRO_KIOSK_ACTIVE) {
                mUtils.log(getString(R.string.error_active_prokiosk));
            } else if (result == CustomDeviceManager.ERROR_POLICY_RESTRICTED) {
                mUtils.log(getString(R.string.error_restricted));
            }
        } catch (SecurityException e) {
            mUtils.processException(e, TAG);
        }
    }       

Disable ProKiosk Mode

This method demonstrates how to use disable ProKiosk Mode.

private void exitProKioskMode() {
        try {
            String defaultPassCode = "12345";
            ProKioskManager proKioskManager = CustomDeviceManager.getInstance().getProKioskManager(); 
	// Instantiate the ProKioskManager class where the setProKioskState method lives
            int result = proKioskManager.setProKioskState(false, defaultPassCode); 
	// Disable ProKiosk Mode and get the result code

            if (result == CustomDeviceManager.SUCCESS) {
                mUtils.log(getString(R.string.exited_prokiosk));
            } else if (result == CustomDeviceManager.ERROR_INVALID_PASSCODE) {
                mUtils.log(getString(R.string.error_passcode));
            } else if (result == CustomDeviceManager.ERROR_PRO_KIOSK_NOT_ACTIVE) {
                mUtils.log(getString(R.string.error_active_prokiosk));
            } else if (result == CustomDeviceManager.ERROR_POLICY_RESTRICTED) {
                mUtils.log(getString(R.string.error_restricted));
            }
        } catch (SecurityException e) {
            mUtils.processException(e, TAG);
        }
    }

Check the ProKiosk Mode state

Check whether the device is in ProKiosk Mode and display the result to the user. Paste the following code in MainActivity().

  private void getProKioskState() {
        try {
            ProKioskManager proKioskManager = CustomDeviceManager.getInstance().getProKioskManager(); 
	// Instantiate the ProKioskManager class where the getProKioskState method lives
            boolean proKioskState = proKioskManager.getProKioskState(); 
	// Get current ProKiosk Mode state, whether it is enabled/disabled
            if (proKioskState) {
                mUtils.log(getString(R.string.prokiosk_enabled));
            } else {
                mUtils.log(getString(R.string.prokiosk_disabled));
            }
        } catch (SecurityException e) {
            mUtils.processException(e, TAG);
        }

Declare the hardware permission in the manifest.

Declare the following permissions in AndroidManifest.xml.

<uses-permission android:name="com.sec.enterprise.knox.permission.CUSTOM_SEALEDMODE"/>
<uses-permission android:name="com.samsung.android.knox.permission.KNOX_APP_MGMT"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

Tutorial Progress

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