Intents
The Magic Leap 2 uses an Android based operating system which provides access to core Android-based features. This section will provide an overview on how developers can use intents to open external activities on the Magic Leap 2.
When developing an Android application, it is possible to call functions to start a service or an activity using an Intent. For example your application can start an external activity for changing user settings. Additionally, intents can contain data that can be used by the receiving activity, for example which settings screen to open within the settings application.
Your code can send intents to the Android system defining the components you are targeting. For example via the startActivity() method you can define that the intent should be used to start an activity. An intent can contain data via a Bundle. This data can be used by the receiving component.
See the Android Intents documentation for more information.
Implicit vs Explicit Intents
There are two types of intents:
Implicit Intents do not directly specify the Android components which should be called, it only specifies the action to be performed. This allows a component from another app to handle the action request. For example, if you want to to ask the user to localize into a map, you can use an implicit intent to launch the Mapping application to handle that request.
Explicit intents specify which application will satisfy the intent, by supplying either the target app's package name or a fully-qualified component class name. Explicit Intents can also be used to pass data to other activity using the
putExtra
method and retrieved by target activity by thegetIntent().getExtras()
methods.
Magic Leap Specific Intents
This section includes a list of Magic Leap specific intents. These can be used to open custom applications such as Fit calibration.
com.magicleap.intent.action.ADJUST_CLIPPING_PLANE
- Opens the Display Zone page and allows the user to adjust the near boundary distance (also known as the near clipping plane setting) and accept or reject the specified setting.
com.magicleap.intent.action.FITTING
- Opens the Eye / Fit Calibration application and guides the user through fit and eye calibration steps. These steps ensure that the user is wearing the headset correctly and that their eyes can be tracked accurately.
com.magicleap.intent.action.EYE_CALIBRATION
- Opens the Eye / Fit Calibrations application and prompts the user to calibrate the headset so the user's eyes can be tracked reliably. If the fit/wear calibration steps have not been complete, the user will be asked to complete the fit calibration first.
com.magicleap.intent.action.EYE_CALIBRATION
- Opens the Eye / Fit Calibrations application and prompts the user to calibrate the headset so the user's eyes can be tracked reliably. If the fit/wear calibration steps have not been complete, the user will be asked to complete the fit calibration first.
com.magicleap.intent.action.IRIS_ENROLLMENT
- Starts the Iris Enrollment from the Settings Menu. If the user has not finished Fit calibration, the user will be ased to run the Fit calibration first. The user can also choose to skip Fit calibration and run Iris Enrollmebt immediatly.
com.magicleap.intent.action.EYE_CALIBRATION_AUTOMATIC
- Starts the Calibration process , even if the user has not completed the Fitting process. Once the calibration app opens, it will ask the user to look at a set of targets to complete eye calibration. When the target scanning is done, the intent will show if the calibration was a Success or Failure then shortly go back to the previous application automatically. No interaction is needed.
com.magicleap.intent.action.SELECT_SPACE
- An Explicit intent that opens the Mapping Tool for the purpose of selecting a space to localize into. It requires being started with startActivityForResult, and also requires the two extras
com.magicleap.intent.extra.SPACE_ID
(The ID of the space you want to localize into) andcom.magicleap.intent.extra.MAPPING_MODE
(Pass 0 for OnDevice and 1 for ARCloud).
- An Explicit intent that opens the Mapping Tool for the purpose of selecting a space to localize into. It requires being started with startActivityForResult, and also requires the two extras
com.magicleap.intent.action.AR_CLOUD_SETTINGS
- This intent opens the device's Perception Settings. From there, users can choose to open the Custom Fit Application or connect to AR Cloud.
Intents can be tested using adb by running the following command from the command line.
adb shell am start -a YOUR_INTENT_HERE
For example:
adb shell am start -a com.magicleap.intent.action.SPACES
Automatic Eye Calibration
You can configure your application so that it automatically launches and goes through the eye calibration process without needing a user to start calibration manually. The intent for automatic eye calibration is:
com.magicleap.intent.action.EYE_CALIBRATION_AUTOMATIC
The application calling the automatic eye calibration intent can retrieve two result codes to know if calibration started successfully: RESULT_OK
and RESULT_CANCELED
. If the result completes successfully, you can check the callback for a success message to verify that calibration completed: data.hasExtra("success")
or get a failure message with data.getExtras().getString("failure")
.
Battery Level
Battery levels for the Compute Pack, Controller, and Power Bank can be obtained using standard Android APIs.
The Native Battery Sample provides an example on obtaining the battery levels for the aforementioned components.
Compute Pack
Developers can access the battery level for the Compute Pack using Android's Battery Manager.
Controller
To obtain the Controller's battery level we use a sticky Intent. Similar to the android intent.action.BATTERY_CHANGED Intent which Android Apps can use to get updates regarding the compute pack battery level and status. Documentation on using the system Intent can be found here: Monitor the Battery Level and Charging State | Android Developers
The Controller battery Intent is named com.magicleap.controller.action.BATTERY_CHANGED. The extras attached to the Intent will follow what the system battery Intent uses, so that code that processes the system battery Intent can be used as the basis for code to process the Controller battery Intent. The following extras are populated in the Controller battery Intent:
- If the connection to the Controller is active, the following extras will be set:
- BatteryManager.EXTRA_PRESENT : true
- BatteryManager.EXTRA_LEVEL : current Controller battery level (0-100)
- BatteryManager.EXTRA_SCALE : 100
- BatteryManager.EXTRA_BATTERY_LOW : true if current level is 25% or lower, otherwise false
- BatteryManager.EXTRA_STATUS : BatteryManager.BATTERY_STATUS_CHARGING or BatteryManager.BATTERY_STATUS_NOT_CHARGING, based on Controller charger connection state
- If the connection to the Controller is not active, the following extras will be set:
- BatteryManager.EXTRA_PRESENT : false
- BatteryManager.EXTRA_STATUS : BatteryManager.BATTERY_STATUS_UNKNOWN
Power Bank
The power level and connection status of a supported Power Bank are populated using sticky Intents. The Power Bank Intent is named com.magicleap.powerbank.action.BATTERY_CHANGED and the extras attached to this Intent are populated as follows:
- If the connection to a supported Power Bank is active:
- BatteryManager.EXTRA_PRESENT : true
- BatteryManager.EXTRA_LEVEL : current Power Bank battery level (0 - 100)
- Otherwise:
- BatteryManager.EXTRA_PRESENT : false
- BatteryManager.EXTRA_LEVEL : -1