Device not in lock task mode, despite CLI setup seemingly successful

I'm trying to set up lock task mode, but my device is continuing to display the home screen with the full list of apps available.

I've setup Android Debug Bridge and followed the online magic leap instructions for setting up Lock Task Mode (links listed at bottom), with an additional first step of removing the existing admin to get the instructions to successfully run from my command line. The four commands I ran successfully are listed below with their corresponding responses from the CLI

adb shell dpm remove-active-admin com.magicleap.locktaskservice/.LockTaskAdminReceiver
Success: Admin removed ComponentInfo{com.magicleap.locktaskservice/com.magicleap.locktaskservice.LockTaskAdminReceiver}

adb shell dpm set-device-owner com.magicleap.locktaskservice/.LockTaskAdminReceiver
Active admin set to component {com.magicleap.locktaskservice/com.magicleap.locktaskservice.LockTaskAdminReceiver}

adb shell am start-service -n com.magicleap.locktaskservice/.LockTaskService -e \ "com.magicleap.locktaskservice.EXTRA_ADD_AND_LAUNCH" "com.MyPackage.package"
Starting service: Intent { cmp=com.magicleap.locktaskservice/.LockTaskService (has extras) }

however, on the device the home screen still shows as usual and the application can be entered and exited as normal. In Settings, I have tried to setup the device to have a Device Lock (since it originally had none), though that did not help. Under Security/ Device admin apps, it lists the LockTaskAdminReceiver and shows it as active. I also cannot deactivate it from the device user interface (which is ideal!). What steps am I missing to get my device to enter my application automatically after being unlocked?

ML2 home button - Unity Development - Magic Leap 2 Developer Forums
Autostart one app after the device is started - Unity Development - Magic Leap 2 Developer Forums

Did you specify the app inside the command that locks the device to the application ?

“com.MyPackage.package”

Lock task mode does not hide applications from the home menu. It simply prevents you from exiting the app. To hide the app you would need to use a custom home menu/ launcher.

Thanks so much for your quick reply!

I specified our application based on its package name in the application/install list.

So even in lock task mode, a user would have to select our application from the home menu after the device is turned on? And they would also still be able to access settings?

Correct, unless the the app is already launched. Which would prevent the user from navigating away from the application.

You could create a custom home menu that would only display a small number of applications or auto launch an app upon startup.


To launch apps and add them to the lock task whitelist:

adb shell am start-service -n com.magicleap.locktaskservice/.LockTaskService -e \
  "com.magicleap.locktaskservice.EXTRA_ADD_AND_LAUNCH" "your.package.name"

Thank you for your response! In summary, after implementing lock task mode I had/have two questions:

  1. How can I get my application to auto-launch at startup?
  2. How can I get my application to not allow the user to exit?

It sounds like (1) is not achieved with Lock Task Mode. Is a custom home menu the only way to auto-launch an application?

It sounds like (2) should be achieved with Lock Task Mode. However, after running that command in the command line, and receiving what I interpreted as a positive response, I also was still able to exit the application as normal by pressing the home button on the handheld controller. This indicates to me that I did not setup Lock Task Mode correctly. Do the responses from the CLI indicate any problems in the steps I executed to implement Lock Task Mode?

The "EXTRA_ADD_AND_LAUNCH" command you've provided seems to match the command in my original attempt (with my application package name swapped in, of course). Which of the two questions was this command was meant to address? Did you see a mistake in my command?

Hey @wrichey!

  1. I do not think this is possible. An alternative would be to use the lock task mode and make a custom home menu. Basically it just shows apps that you want it to show on the home menu.
  2. Using lock task mode will achieve this behavior

Let's say you want to have the magic leap examples app be the only app that shows on your home menu and not allow the user to press the home button to go back to the home menu once the app has been launched.

Important note: any adb command you run, please ensure it is formatted to 1 line with no line breaks. If there are line breaks you might run into errors.

To do this, you can utilize lock task mode like so:

  1. Ensure you have USB debugging enabled on your device, you can follow this guide
    Enable Developer Mode | MagicLeap Developer Documentation
  2. Give the lock task service admin permissions with the following adb command

adb shell dpm set-device-owner com.magicleap.locktaskservice/.LockTaskAdminReceiver

  1. To start the lock task service AND launch an app at the same time, use the following adb command. Take note that the package name of the app is required,com.magicleap.unity.examples. If the app you are trying to launch is a Unity app, you will need to add /com.unity3d.player.UnityPlayerActivity to the package name as well.

adb shell am start-service -n com.magicleap.locktaskservice/.LockTaskService -e "com.magicleap.locktaskservice.EXTRA_ADD_AND_LAUNCH" "com.magicleap.unity.examples/com.unity3d.player.UnityPlayerActivity"

  1. When you are ready to stop using the device in lock task mode, you can use the following adb command to return the device to normal operations. Here you use the com.magicleap.locktaskservice.EXTRA_REMOVE_PACKAGE intent along with the package name of your app

adb shell am start-service -n com.magicleap.locktaskservice/.LockTaskService -e "com.magicleap.locktaskservice.EXTRA_REMOVE_PACKAGE" "com.magicleap.unity.examples"

This document goes over all of this if you would like to get more information!

Please let us know if this works for you!

1 Like

Thank you!! I was missing the activity in step 3 when calling start-service. This is, admittedly in blue with an exclamation point on the page that you linked. I don't know how I missed it.

com.MyPackage.package*/com.unity3d.player.UnityPlayerActivity*

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.