Skip to content
On this page

App相关

javascript
//Node版引擎导入方式
import core from 'cheese-node';
//JS版引擎导入方式
const core = require('cheese-js');

获取前台包名: ` public static getForegroundPkg(): string ✅

返回值:

  • 🟢string: 包名
  • 🔴 null

用法示例:

javascript
const app = core.app;
console.log("前台包名",app.getForegroundPkg())

获取前台类名: ` public static getForegroundCls(): string ✅

返回值:

  • 🟢string: 类名
  • 🔴 null

用法示例:

javascript
const app = core.app;
console.log("前台类名",app.getForegroundCls())

用浏览器打开网站: ` public static openUrl(url: string): void ✅

参数:

  • string (url): 网站的Url。如果不以 "http://" 或 "https://" 开头,则默认是 "http://"

用法示例:

javascript
const app = core.app;
app.openUrl("https://www.example.com")

卸载应用: public static uninstall(pkg: string): void

参数:

  • string (pkg): 目标包名

用法示例:

javascript
const app = core.app;
app.uninstall("com.example.package")

获取应用名称对应的已安装的应用的包名: public static getPackageName(appName:string): string

参数:

  • string (appName): 应用名称

返回值:

  • 🟢string: 应用包名
  • 🔴 null

用法示例:

javascript
const app = core.app;
const packageName = app.getPackageName("Cheese");
console.log("包名", packageName);

获取应用包名对应的已安装的应用的名称: public static getAppName(packageName:string): string

参数:

  • string (pkg): 目标包名

返回值:

  • 🟢string: 应用名称
  • 🔴 null

用法示例:

javascript
const app = core.app;
const appName = app.getAppName("com.example.app");
console.log("应用名称", appName);

打开App设置页面: public static openAppSettings(packageName: string): boolean

参数:

  • string (packageName): 目标包名

返回值:

  • 🟢boolean: true
  • 🔴boolean: false

用法示例:

javascript
const app = core.app;
if (app.openAppSettings("com.example.app")) {
    console.log("成功");
}

包名打开app: public static openApp(pkg: string): boolean

参数:

  • string (pkg):包名

返回值:

  • 🟢boolean:true
  • 🔴boolean:fasle

用法示例:

javascript
const app = core.app;
if (app.openApp("com.sm")) {
    console.log("成功");
}

打开Scheme: openScheme(schemeUri: string): boolean

参数:

  • string (schemeUri): Scheme字符串

返回值:

  • 🟢boolean: true
  • 🔴boolean: false

用法示例:

javascript
const app = core.app;
if (app.openScheme("sms://")) {
    console.log("成功");
}