Action.launch()

Overview

Launches an Android Activity that allows the Client to interact with other software loaded on the device.

Calls to Action.launch() are asynchronous and the script will continue to execute even though the activity has not returned.

Activities are started using intents. The intent is represented as a JavaScript object with certain properties.

  • Intents must have at least an action or a class and package combination.
  • If multiple applications match the intent, a chooser dialog will appear.

Format

Action.launch(intent);

Intent object properties

Value Description Type Required Notes
action A string representing the action to be performed. String Optional If the device has multiple apps registered to handle an action, a chooser dialog appears.
categories A list of required categories for the activity that is being started. Array of strings Optional
class The name of the activity class to explicitly launch. If the devices are Android 11 or newer, you must include a package name with the class. String Optional Must be used with package.
package The name of the application package to explicitly launch. If the devices are Android 11 or newer, you must include a class name with the package. String Optional Must be used with class.
data The data URI that the action will operate on. If the devices are Android 11 or newer, you must include a class name with the package String Optional Must be a URI formatted string. For example:
"http://www.wavelink.com/"
"file:///sdcard/file.dat"

In Android 11 or newer, the Velocity client has very limited access to the file system.


Added in version 2.1.1
mime The explicit MIME type of the data, or, if no data is specified, a request for a specific MIME type result. String Optional Rarely used.
For example:
"text\plain"
Added in version 2.1.1
extras Passes additional data to the invoked app. Array of objects Optional

See the description for Extras in the table below.

flags A list of flags to be passed to the launch intent. Array of strings Optional For a list of possible flags, see https://learn.microsoft.com/en-us/dotnet/api/android.content.activityflags?view=xamarin-android-sdk-13

Extras

Value Description Type Required Notes
name The name of the extra. String Required  
value The value of the extra. String, Integer, Boolean, Array of String, Array of Integer, Array of Boolean Required Arrays added in version 2.1.11
type The value type. One of "string", "integer", or "boolean". String Optional If not specified a type will be assigned based on the JavaScript type of the value or the JavaScript type of the first value in arrays. For arrays use the same three types to represent the type for all values in the array.

Example 1

Copy
/* Start the calculator activity.
 */
Action.launch({
    action:'android.intent.action.MAIN',
    categories:['android.intent.category.APP_CALCULATOR']
});

Example 2

Copy
/* Start the RXLogger activity.
 */
Action.launch({
    action:'android.intent.action.MAIN',
    package: "com.symbol.rxlogger",
    class: "com.symbol.rxlogger.MainActivity",
});

Example 3

Copy
/* Start a web browser and navigate to Ivanti's web page.
 */
Action.launch({
    action:'android.intent.action.VIEW',
    data: "http://www.ivanti.com"
});

Example 4

Copy
/* Send an email to multiple recipients.
 */

Action.launch({
    action: "android.intent.action.SENDTO",
    data: "mailto:",
    extras: [
        {name: "android.intent.extra.EMAIL", value: ["[email protected]", "[email protected]"], type: "string"},
        {name: "android.intent.extra.SUBJECT", value: "Email subject", type: "string"},
        {name: "android.intent.extra.TEXT", value: "Hello, this is the body of the email being sent.", type: "string"}
    ]
});

Example 5

Copy
/* Start the RXLogger activity with the ClearTop and ClearTask intent flags
 */
Action.launch({
action:'android.intent.action.MAIN',
    package: "com.symbol.rxlogger",
    class: "com.symbol.rxlogger.MainActivity",
    flags: ['ClearTop', 'ClearTask']
});