Menu

Turn on Kiosk 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/disable default Kiosk Mode

This method demonstrates how to toggle Kiosk Mode.

private void toggleKiosk () {
        try {
            EnterpriseDeviceManager enterpriseDeviceManager = EnterpriseDeviceManager.getInstance(this);
	// Instantiate the EnterpriseDeviceManager class	               	  
	KioskMode kioskMode = enterpriseDeviceManager.getKioskMode
	// Get the KioskMode object where the enable/disableKioskMode method lives
            boolean kioskState = kioskMode.isKioskModeEnabled();

            if (kioskState) { // If in Kiosk Mode, disable Kiosk Mode
                mUtils.log(getString(R.string.leaving_kiosk));
                removeShortcutFromKioskMode();
                kioskMode.disableKioskMode();
            } else { // If not in Kiosk Mode, enable Kiosk Mode with the current package as the home package
                mUtils.log(getString(R.string.entering_kiosk));
                kioskMode.enableKioskMode();
            }
        } catch (SecurityException e) {
            mUtils.processException(e, TAG);
        }
    }

Enable/disable custom Kiosk Mode

This method demonstrates how to use custom Kiosk Mode.

private void toggleCustomKiosk (KioskSetting kioskSetting) {
        try {
            EnterpriseDeviceManager enterpriseDeviceManager = EnterpriseDeviceManager.getInstance(this); 
	// Instantiate the EnterpriseDeviceManager class
            KioskMode kioskMode = enterpriseDeviceManager.getKioskMode(); 
	// Get the KioskMode object where the enable/disableKioskMode method lives

            boolean kioskState = kioskMode.isKioskModeEnabled();

            if (kioskState) { // If in Kiosk Mode, disable Kiosk Mode
                mUtils.log(getString(R.string.leaving_kiosk));
                removeShortcutFromKioskMode();
                kioskMode.disableKioskMode(kioskSetting);
            } else { // If not in Kiosk Mode, enable Kiosk Mode with provided Kiosk Mode settings
                mUtils.log(getString(R.string.entering_kiosk));
                kioskMode.enableKioskMode(kioskSetting);
            }
        } catch (SecurityException e) {
            mUtils.processException(e, TAG);
        }
    }

		

Prompt the user to configure settings for entering Kiosk Mode.

For example – the user can disable changing settings and expanding the status bar in Kiosk Mode.

private void promptCustomKioskSetting() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this); // Build a dialog to show the user
        builder.setTitle(getString(R.string.configure_kiosk_setting)); // WIth the title "Configure Certificate"
        View viewInflated = LayoutInflater.from(this).inflate(R.layout.prompt_kiosk_setting, (ViewGroup) findViewById(R.id.kiosk_config_group), false);

        final CheckBox chkSettingsChanges = (CheckBox) viewInflated.findViewById(R.id.chkSettingsChange);
        final CheckBox chkStatusBar = (CheckBox) viewInflated.findViewById(R.id.chkAllowStatusBar);
        final CheckBox chkStatusBarExpansion = (CheckBox) viewInflated.findViewById(R.id.chkStatusBarExpansion);
        final CheckBox chkSystemBar = (CheckBox) viewInflated.findViewById(R.id.chkAllowSystemBar);
        final CheckBox chkTaskManager = (CheckBox) viewInflated.findViewById(R.id.chkAllowTaskManager);
        final CheckBox chkHomekey = (CheckBox) viewInflated.findViewById(R.id.chkAllowHomekey);
        final CheckBox chkAirCommand = (CheckBox) viewInflated.findViewById(R.id.chkAllowAirCommand);
        final CheckBox chkAirView = (CheckBox) viewInflated.findViewById(R.id.chkAllowAirview);
        final CheckBox chkMultiwindow = (CheckBox) viewInflated.findViewById(R.id.chkAllowMultiwindow);
        final CheckBox chkSmartclip = (CheckBox) viewInflated.findViewById(R.id.chkAllowSmartClip);
        final CheckBox chkNavBar = (CheckBox) viewInflated.findViewById(R.id.chkAllowNavBar);
        final CheckBox chkWipeRecentTasks = (CheckBox) viewInflated.findViewById(R.id.chkWipeRecentTasks);
        final CheckBox chkClearNotifications = (CheckBox) viewInflated.findViewById(R.id.chkClearNotifications);

        builder.setView(viewInflated);
        builder.setPositiveButton(getString(R.string.option_confirm), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                KioskSetting kioskSetting = new KioskSetting();
                kioskSetting.settingsChanges = chkSettingsChanges.isChecked();
                kioskSetting.statusBar = chkStatusBar.isChecked();
                kioskSetting.statusBarExpansion = chkStatusBarExpansion.isChecked();
                kioskSetting.systemBar = chkSystemBar.isChecked();
                kioskSetting.taskManager = chkTaskManager.isChecked();
                kioskSetting.homeKey = chkHomekey.isChecked();
                kioskSetting.airCommand = chkAirCommand.isChecked();
                kioskSetting.airView = chkAirView.isChecked();
                kioskSetting.multiWindow = chkMultiwindow.isChecked();
                kioskSetting.smartClip = chkSmartclip.isChecked();
                kioskSetting.navigationBar = chkNavBar.isChecked();
                kioskSetting.wipeRecentTasks = chkWipeRecentTasks.isChecked();
                kioskSetting.clearAllNotifications = chkClearNotifications.isChecked();

                toggleCustomKiosk(kioskSetting);
            }
        });

        builder.setNegativeButton(getString(R.string.option_cancel), new DialogInterface.OnClickListener() 	{
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();
    }            

		

Add/remove app shortcut to Kiosk Mode

Paste the following code in MainActivity() to add shortcut.

           
public void addShortcutToKioskMode() {
        EnterpriseDeviceManager enterpriseDeviceManager = EnterpriseDeviceManager.getInstance(this); 
	// Instantiate the EnterpriseDeviceManager class
        ApplicationPolicy applicationPolicy = enterpriseDeviceManager.getApplicationPolicy(); 
	// Get the ApplicationPolicy object where the addHomeShortcut method lives
        KioskMode kioskMode = enterpriseDeviceManager.getKioskMode(); 
	// Get the KioskMode object where the getKioskHomePackage method lives

        try {
            String kioskHomePackage = kioskMode.getKioskHomePackage(); 
	// Get the Kiosk home package

            boolean result = applicationPolicy.addHomeShortcut(getPackageName(), kioskHomePackage);
	 // Add the sample app shortcut to the Kiosk home package
            if (result) {
                mUtils.log(getString(R.string.added_app_to_kiosk));
            } else {
                mUtils.log(getString(R.string.failed_add_app_to_kiosk));
            }
        } catch (SecurityException e) {
            mUtils.processException(e, TAG);
        }
    }          

Paste the following code in MainActivity() to remove shortcut.

           
			public void removeShortcutFromKioskMode() {
        EnterpriseDeviceManager enterpriseDeviceManager = EnterpriseDeviceManager.getInstance(this); 
	// Instantiate the EnterpriseDeviceManager class
        ApplicationPolicy applicationPolicy = enterpriseDeviceManager.getApplicationPolicy(); 
	// Get the ApplicationPolicy object where the removeHomeShortcut method lives
        KioskMode kioskMode = enterpriseDeviceManager.getKioskMode(); 
	// Get the KioskMode object where the getKioskHomePackage method lives

        try {
            String kioskHomePackage = kioskMode.getKioskHomePackage(); 
	// Get the Kiosk home package

            boolean result = applicationPolicy.deleteHomeShortcut(getPackageName(), kioskHomePackage); 
	// Add the sample app shortcut to the Kiosk home package
            if (result) {
                mUtils.log(getString(R.string.removed_app_from_kiosk));
            } else {
                mUtils.log(getString(R.string.failed_remove_app_kiosk));
            }
        } 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.example.supportlibclient.SUPPORT_PERMISSION" />
			<uses-permission android:name="com.samsung.android.knox.permission.KNOX_KIOSK_MODE"/>
			<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 7/8 done! Go to the next step.