Dedicated devices

Glass is typically configured to be used as a dedicated device with a small number of applications that make up an enterprise solution. The following guide demonstrates how to set up Glass as a dedicated device.

Provisioning

Low-touch provisioning on Glass Enterprise Edition 2 installs and configures an admin application that's downloaded from the metadata provided in a QR code. This application can take advantage of the DevicePolicyManager API, which is the preferred method to manage the device’s configuration.

Replace launcher

To set up a dedicated device, you must replace the launcher application. This ensures that the dedicated application is launched automatically after the device reboots. The following content outlines the tasks involved in preparing an application and setting it as the launcher:

  • Activity intent filter
  • Set a new launcher
  • Activity intent filter

    You need to add the following categories to the main activity in your application's manifest:

    <intent-filter>
      <action android:name="android.intent.action.MAIN"/>
      <category android:name="android.intent.category.LAUNCHER"/>
    
      <category android:name="android.intent.category.HOME"/>
      <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>

    Set a new launcher

    To set a new launcher, call addPersistentPreferredActivity() from the admin application. This only works if the device has already been provisioned. For non-provisioned devices, select a new launcher from the UI on the device.

    Add persistent preferred activity

    This method allows you to set a given componentName as the device’s launcher, without interacting with the device.

    Kotlin

    val filter = IntentFilter(Intent.ACTION_MAIN)
    filter.addCategory(Intent.CATEGORY_HOME)
    filter.addCategory(Intent.CATEGORY_DEFAULT)
    
    val componentName = ComponentName(PACKAGE_NAME, CLASS_NAME)
    val devicePolicyManager: DevicePolicyManager =
        context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
    val adminName = getComponentName(context)
    devicePolicyManager.addPersistentPreferredActivity(adminName, filter, componentName)

    Java

    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);
    filter.addCategory(Intent.CATEGORY_DEFAULT);
    
    final ComponentName componentName = new ComponentName(PACKAGE_NAME, CLASS_NAME);
    DevicePolicyManager devicePolicyManager =
        (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    final adminName = getComponentName(context);
    devicePolicyManager.addPersistentPreferredActivity(adminName, filter, componentName);

    Use UI on the device

    Use one of the following methods to show a launcher selection dialog on the screen:

    Using swipe up touch gesture in settings

    Swipe backwards on the home screen to show a settings summary screen. Then, tap to enter the settings screen. Swipe up to show the dialog.

    Using intent in the application

    Kotlin

    val intent = Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);

    Java

    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    startActivity(intent);
    Using adb command

    adb shell am start -a android.intent.action.MAIN -c android.intent.category.HOME

    Swipe forward and backward on the touchpad to select your preferred application and tap to confirm. Use the same method to select the "Always" button.

    Lock task mode

    Lock task mode allows you to create a list of packages that are permitted to run on the device.

    Set permitted packages

    The following snippet shows you how to set the list of packages:

    Kotlin

    private val KIOSK_PACKAGE = "com.example.kiosk"
    private val PLAYER_PACKAGE = "com.example.player"
    private val APP_PACKAGES = arrayOf(KIOSK_PACKAGE, PLAYER_PACKAGE)
    
    val devicePolicyManager: DevicePolicyManager =
      context.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
    val adminName = getComponentName(context)
    devicePolicyManager.setLockTaskPackages(adminName, APP_PACKAGES)

    Java

    private static final String KIOSK_PACKAGE = "com.example.kiosk";
    private static final String PLAYER_PACKAGE = "com.example.player";
    private static final String[] APP_PACKAGES = {KIOSK_PACKAGE, PLAYER_PACKAGE};
    
    final DevicePolicyManager devicePolicyManager =
        (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    final ComponentName adminName = getComponentName(context);
    devicePolicyManager.setLockTaskPackages(adminName, APP_PACKAGES);

    Start lock task mode

    Lock task mode can be started by the application's activity. The following snippet shows how you can do this:

    Kotlin

    override fun onResume() {
        super.onResume()
        activity.startLockTask()
    }

    Java

    @Override
    public void onResume() {
      super.onResume();
      getActivity().startLockTask();
    }