app
app
The app module provides a set of functions to use other applications and interact with other applications. For example, sending intents, opening files, sending emails, etc.
It also provides convenient advanced functions startActivity and sendBroadcast, which can be used to do interactions with other applications that are not built into the app module.
app.versionCode
- {number}
Current software version number, integer value. For example, 160, 256, etc.
If running in CloudControl, it is the version number of CloudControl; in packaged software, it is the version number of the packaged software.
toastLog(app.versionCode);
app.versionName
- {string}
The current software version name, e.g. "3.0.0 Beta".
This is the version name of CloudControl if running in CloudControl, or the version name of the packaged software if running in a packaged software.
toastLog(app.versionName);
CloudControl version name, e.g. "3.0.0 Beta".
app.launchApp(appName)
appName
{string} The name of the application.
Launches the app by its name. Returns false if the app corresponding to the name does not exist, or true if the name corresponds to more than one app, then only one of them will be launched.
This function can also be used as a global function.
launchApp("云控");
app.launch(packageName)
- ``packageName` {string} Application package name
Launches the application by its package name. Returns false if the application corresponding to the package name does not exist; otherwise, returns true.
This function can also be used as a global function.
//launch WeChat
launch("com.tencent.mm");
app.launchPackage(packageName)
packageName
{string} Application package name
Equivalent to app.launch(packageName)
.
app.getPackageName(appName)
appName
{string} the name of the application
Get the package name of the installed app corresponding to the app name. If the app is not found, return null; if the name corresponds to more than one app, return the package name of only one of them.
This function can also be used as a global function.
var name = getPackageName("QQ"); //returns "com.tencent.mobileqq"
app.getAppName(packageName)
packageName
{string} The name of the app package
Get the name of the installed app corresponding to the app package name. If the app is not found, return null.
This function can also be used as a global function.
var name = getAppName("com.tencent.mobileqq"); //returns "QQ"
app.openAppSetting(packageName)
- ``packageName` {string} Application package name
Open the app's details page (settings page). Returns false if the app is not found; otherwise returns true.
This function can also be used as a global function.
app.viewFile(path)
path
{string} file path
View the file with another application. The case that the file does not exist is handled by the application that viewed it.
If no application can be found that can view the file, ActivityNotException
is thrown.
//Viewing a text file
app.viewFile("/sdcard/1.txt");
app.editFile(path)
path
{string} file path
Edit the file with another application. The case that the file does not exist is handled by the application that edited the file.
If no application can be found that can edit the file, ActivityNotException
is thrown.
// Edit a text file
app.editFile("/sdcard/1.txt/);
app.uninstall(packageName)
packageName
{string} Application package name
Uninstall the application. After execution, a popup box will appear to uninstall the application. If the application of this package name is not installed, it will be handled by the application uninstaller, which may pop up a "Application not found" message.
//Uninstall QQ
app.uninstall("com.tencent.mobileqq");
app.openUrl(url)
url
{string} Url of the website, or by default "http://" if it doesn't start with "http://" or "https://".
Open the website url with a browser.
If no browser application is installed, ActivityNotException
is thrown.
app.sendEmail(options)
options
{Object} The parameters to send the email. Include :email
{string} | {Array} The email address of the recipient. If there is more than one recipient, it will be represented as an array of stringscc
{string} | {Array} The email address of the cc recipient. If there is more than one cc recipient, it is represented as an array of stringsbcc
{string} | {Array} The email address of the bcc recipient. If there is more than one bcc recipient, it is represented as an array of stringssubject
{string} The subject of the message.text
{string} The body of the message.attachment
{string} The path of the attachment.
The mailbox application is invoked to send the message based on the optionsoptions. These options are optional.
If the mailbox app is not installed, ActivityNotException
is thrown.
//发送邮件给10086@qq.com和10001@qq.com.
app.sendEmail({
email: ["10086@qq.com", "10001@qq.com"],
subject: "This is an email subject",
text: "This is the body of the email"
});
app.startActivity(name)
name
{string} The name of the activity, with the optional value :console
logging interfacesettings
settings interface
Starts CloudControl with a specific interface. This function will open the interface within CloudControl if run from within CloudControl, or the corresponding interface of the packaged application if run from within the packaged application.
app.startActivity("console");
Advanced: Intent
An Intent (intent) is a messaging object that you can use to request actions from other application components. While Intent can facilitate communication between components in a variety of ways, its basic use cases include three main ones.
-
Launching an activity (Activity). An Activity represents a "screen" in an application. By passing an Intent to startActivity(), you can start a new instance of Activity. The Intent describes the Activity to be started and carries any necessary data.
-
Start a Service (Service). A Service is a component that performs operations in the background without using the user interface. You can start a service to perform a one-time operation (for example, downloading a file) by passing an Intent to startService(). the Intent describes the service to be started and carries any necessary data.
-
Passing a broadcast. Broadcasts are messages that can be received by any application. The system will deliver various broadcasts in response to system events (for example, when the system starts up or when a device starts charging). You can pass broadcasts to other applications by passing the Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
This module provides functions for building Intent (app.intent()
), starting Activity (app.startActivity()
), and sending broadcasts (app.sendBroadcast()
).
Using these methods can be used to easily call other applications. For example, open the personal card page of a QQ number directly, open the chat window of a QQ number, etc.
var qq = "2874662633";
app.startActivity({
action: "android.intent.action.VIEW",
data: "mqq://im/chat?chat_type=wpa&version=1&src_type=web&uin=" + qq,
packageName: "com.tencent.mobileqq",
});
app.intent(options)
options
{Object} options, including.-
action
{string} The intended Action, which refers to the action intended to be completed, is a string constant, such as "android.intent.action.SEND". When the action starts with "android.intent.action", you can omit the prefix and use "SEND" instead. See Actions. -
type
{string} The MimeType of the intent, indicating the type of the data directly related to the intent, e.g. "text/plain" for plain text. -
data
{string} The Data of the intent, which is the data directly related to the intent, is a Uri, which can be a file path or Url, etc. For example, to open a file, action is "android.intent.action.VIEW", data is "file:///sdcard/1.txt". -
category
{Array} The category of the intent. Used relatively rarely. See Categories. -
packageName
{string} The name of the target package. -
className
{string} The name of the target component such as Activity or Service. -
extras
{Object} Extras (additional information) for this Intent composed as a key-value pair. Provides additional information about this Intent, such as the email title, email body when sending the email. See Extras. -
flags
{Array} The identifier of the intent, an array of strings, e.g.["activity_new_task", "grant_read_uri_permission"]
. See Flags.
-