# mt.addShortcut(Object object)
添加桌面快捷方式。
# 支持情况
| 项 | 说明 |
|---|---|
| 兼容性 | 美团小游戏特有 |
# 参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| shortcutType | number | 2 | 否 | 快捷方式类型:1 动态快捷方式(Android 7.0+),2 常规桌面快捷方式,3 桌面小插件 |
| id | string | — | 是 | 快捷方式唯一标识 |
| label | string | — | shortcutType=1/2 时必填 | 快捷方式显示名称 |
| icon | string | — | 否 | 快捷方式图标 |
| target | string | — | shortcutType=1/2 时必填 | 快捷方式跳转目标页面 |
| widgetProviderId | string | — | shortcutType=3 时必填 | 桌面小插件唯一标识 |
| interceptSuccess | boolean | false | 否 | 是否拦截添加成功提示,由业务自行处理 |
| success | function | — | 否 | 成功回调 |
| fail | function | — | 否 | 失败回调 |
| complete | function | — | 否 | 完成回调(成功或失败均触发) |
# 返回值
无返回值
# 示例代码
mt.addShortcut({
id: 'game_shortcut_001',
label: '我的游戏',
target: 'pages/index/index',
shortcutType: 2,
success() {
console.log('快捷方式添加成功')
},
fail(err) {
console.error(err.errMsg)
}
})
# 与微信差异
此 API 为美团小游戏特有,微信小游戏中无对应接口。