This namespace contains Android-specific APIs, like Intents and Bundles.
- Since:
Classes
Members
-
static, readonly IntentStatusCode :object
-
This enumeration represents an error status code of mobicontrol.android.IntentError.
Properties:
Name Type Description UNKNOWNobject The reason for the error is unknown. COMPONENT_NOT_FOUNDobject No component found to run the given intent, or there are no permissions to access the component. ILLEGAL_STATEobject The component is in a state where the service cannot be started. ACTIVITY_CANCELEDobject The activity called for result explicitly returned RESULT_CANCELED, didn't return any result, or crashed during its operation. NEW_ACTIVITY_STARTEDobject 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:
-
static, readonly UriStatusCode :object
-
This enumeration represents an error status code of mobicontrol.android.UriError.
Properties:
Name Type Description UNKNOWNobject The reason for the error is unknown. ILLEGAL_ARGUMENTobject An argument passed into URI creation function is invalid. - Since:
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:
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 filemobicontrol.io.File A Filefor 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:
-
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:
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 uriStringstring An RFC 2396-compliant, encoded URI. Returns:
mobicontrol.android.Uri - URI for the given string.- Since:
-
static resolveDefaultActivity(intent) → {mobicontrol.app.Activity}
-
Retrieve the default activity which handles the given intent.
Parameters:
Name Type Description intentmobicontrol.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:
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 intentmobicontrol.android.Intent Intent for sending a broadcast. Throws:
- Since:
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 intentmobicontrol.android.Intent The description of the activity to start. Throws:
- Since:
-
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
startActivityForResultwill cancel a previous call, even if the latter was done from a different script. This will cause the previous callback to fail withNEW_ACTIVITY_STARTEDerror code. See also Intents tutorial.Parameters:
Name Type Attributes Description intentmobicontrol.android.Intent The description of the activity to start. callbackFunctionmobicontrol.android.startActivityForResultCallback JavaScript function which is called when the activity finishes. invocationTimeoutInMillisnumber <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:
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 intentmobicontrol.android.Intent Intent for starting a service. Throws:
- Since:
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 resultobject Result of the activity. Properties
Name Type Description intentmobicontrol.android.Intent Result data returned by activity. This value may be null.requestmobicontrol.android.Intent The intent provided to the mobicontrol.android.startActivityForResult method. errormobicontrol.android.IntentError Detailed error conditions in case of failure. This value is nullwhen the callback is successful or when there is a timeout.isSuccessfulboolean Success status of the callback. trueif the callback completed successfully,falseotherwise.isTimedOutboolean Timeout status of the callback. trueif the callback was timed out,falseotherwise. Note: A timeout is considered a failure, so if the timeout status istrue, failure status istrueas well, and success status isfalse.isFailedboolean Failure status of the callback. trueif the callback failed,falseotherwise.- Since: