This namespace contains Android-specific APIs, like Intents and Bundles.
- Since:
- Version 1.8 (API level 9)
Classes
Members
-
static, readonly IntentStatusCode :object
-
This enumeration represents an error status code of mobicontrol.android.IntentError.
Properties:
Name Type Description UNKNOWN
object The reason for the error is unknown. COMPONENT_NOT_FOUND
object No component found to run the given intent, or there are no permissions to access the component. ILLEGAL_STATE
object The component is in a state where the service cannot be started. ACTIVITY_CANCELED
object The activity called for result explicitly returned RESULT_CANCELED, didn't return any result, or crashed during its operation. NEW_ACTIVITY_STARTED
object Reported by mobicontrol.android.startActivityForResult for the current activity, when a new activity was started for result while the current activity didn't finish yet. - Since:
- Version 1.8 (API level 9)
-
static, readonly UriStatusCode :object
-
This enumeration represents an error status code of mobicontrol.android.UriError.
Properties:
Name Type Description UNKNOWN
object The reason for the error is unknown. ILLEGAL_ARGUMENT
object An argument passed into URI creation function is invalid. - Since:
- Version 1.8 (API level 9)
Methods
-
static createBundle() → {mobicontrol.android.Bundle}
-
Create an empty bundle. To build useful bundles, combine this function with one or more bundle setter functions.
Returns:
mobicontrol.android.Bundle - An empty bundle.- Since:
- Version 1.8 (API level 9)
Example
// Insert a new contact into the address book var extras = mobicontrol.android.createBundle(). withString("name", "John Doe"). withString("email", "johndoe@example.com"). withString("phone", "416-555-0111"); var intent = mobicontrol.android.createIntent(). withAction("android.intent.action.INSERT"). withData("content://com.android.contacts/contacts"). withExtras(extras); mobicontrol.android.startActivity(intent);
-
static createFileContentUri(file) → {mobicontrol.android.Uri}
-
Create a file content URI.
Parameters:
Name Type Description file
mobicontrol.io.File A File
for which a content URI is requested. Note: Avoid using files outside the agent's internal storage, as those might not be accessible.Throws:
Returns:
mobicontrol.android.Uri - File content URI for the given file.- Since:
- Version 1.8 (API level 9)
-
static createIntent() → {mobicontrol.android.Intent}
-
Create an empty intent. To build useful intents, combine this function with one or more intent setter functions, as in the provided example.
Returns:
mobicontrol.android.Intent - An empty intent.- Since:
- Version 1.8 (API level 9)
Example
// Start a camera app in still image mode, see https://developer.android.com/guide/components/intents-common#CameraStill var intent = mobicontrol.android.createIntent().withAction("android.media.action.STILL_IMAGE_CAMERA"); mobicontrol.android.startActivity(intent);
-
static createUri(uriString) → {mobicontrol.android.Uri}
-
Create a URI from the given encoded URI string.
Parameters:
Name Type Description uriString
string An RFC 2396-compliant, encoded URI. Returns:
mobicontrol.android.Uri - URI for the given string.- Since:
- Version 1.8 (API level 9)
-
static resolveDefaultActivity(intent) → {mobicontrol.app.Activity}
-
Retrieve the default activity which handles the given intent.
Parameters:
Name Type Description intent
mobicontrol.android.Intent An intent for which the default activity is retrieved. Returns:
mobicontrol.app.Activity - The default activity to handle the intent, or null if no matching activity found.- Since:
- Version 1.8 (API level 9)
Example
var intent = mobicontrol.android.createIntent() .withData("http://example.com") .withAction("android.intent.action.VIEW"); var activity = mobicontrol.android.resolveDefaultActivity(intent); mobicontrol.log.info("The default Web browser is " + activity.packageName);
-
static sendBroadcast(intent)
-
Send out a broadcast. See also Intents tutorial.
Parameters:
Name Type Description intent
mobicontrol.android.Intent Intent for sending a broadcast. Throws:
- Since:
- Version 1.8 (API level 9)
Example
// Install a system update on an encrypted Motorola device var extras = mobicontrol.android.createBundle() .withString('file', '/sdcard/Download/update.zip'); var intent = mobicontrol.android.createIntent() .withAction('com.motorolasolutions.intent.action.UPDATE_PACKAGE') .withExtras(extras); mobicontrol.android.sendBroadcast(intent);
-
static startActivity(intent)
-
Launch a new activity. FLAG_ACTIVITY_NEW_TASK will always be added to flags specified in the intent, as the script never runs in Android activity context. On Android 10 and above, when a non-device owner agent is running in the background, SYSTEM_ALERT_WINDOW permission must be granted in order to start the activity; otherwise, this call will do nothing. For example, this permission can be granted during agent enrollment by configuring the enrollment rule with Draw Over Other Apps permission. See also Intents tutorial.
Parameters:
Name Type Description intent
mobicontrol.android.Intent The description of the activity to start. Throws:
- Since:
- Version 1.8 (API level 9)
-
async, static startActivityForResult(intent, callbackFunction, invocationTimeoutInMillisopt)
-
Launch a new activity, returning the activity result in a callback result parameter. We can only wait for the result of one activity at a time. Any new call to
startActivityForResult
will cancel a previous call, even if the latter was done from a different script. This will cause the previous callback to fail withNEW_ACTIVITY_STARTED
error code. See also Intents tutorial.
Parameters:
Name Type Attributes Description intent
mobicontrol.android.Intent The description of the activity to start. callbackFunction
mobicontrol.android.startActivityForResultCallback JavaScript function which is called when the activity finishes. invocationTimeoutInMillis
number <optional>
Invocation timeout in milliseconds. If the callback function isn't invoked before the timeout expires, it will be called with the timed-out result. - Since:
- Version 1.8 (API level 9)
Example
var intent = mobicontrol.android.createIntent() .withAction("android.intent.action.GET_CONTENT") .withType("image/*"); mobicontrol.android.startActivityForResult(intent, onFilePicked); function onFilePicked(result) { if (result.isSuccessful) { mobicontrol.log.info("The file '" + result.intent.data + "' is picked!"); } }
-
static startService(intent)
-
Start a service.
Parameters:
Name Type Description intent
mobicontrol.android.Intent Intent for starting a service. Throws:
- Since:
- Version 1.8 (API level 9)
Example
// Play an audio file in the background with specified volume var extras = mobicontrol.android.createBundle(). withString("file", "audiobook.mp3"). withLong("volume", 70); var intent = mobicontrol.android.createIntent(). withComponent("com.example.app/.MediaPlayerService"). withExtras(extras); mobicontrol.android.startService(intent);
Type Definitions
-
startActivityForResultCallback(result)
-
Callback function for mobicontrol.android.startActivityForResult.
Parameters:
Name Type Description result
object Result of the activity. Properties
Name Type Description intent
mobicontrol.android.Intent Result data returned by activity. This value may be null
.request
mobicontrol.android.Intent The intent provided to the mobicontrol.android.startActivityForResult method. error
mobicontrol.android.IntentError Detailed error conditions in case of failure. This value is null
when the callback is successful or when there is a timeout.isSuccessful
boolean Success status of the callback. true
if the callback completed successfully,false
otherwise.isTimedOut
boolean Timeout status of the callback. true
if the callback was timed out,false
otherwise. Note: A timeout is considered a failure, so if the timeout status istrue
, failure status istrue
as well, and success status isfalse
.isFailed
boolean Failure status of the callback. true
if the callback failed,false
otherwise.- Since:
- Version 1.8 (API level 9)