赞
踩
Ba-Shortcut 是一款App Shortcuts(安卓快捷方式)插件。Shortcuts是指在桌面长按app图标而出现的快捷方式, 可以为你的app的关键功能添加更快速的入口而不用先打开app,点击快捷方式可以访问应用功能, 并且这种快捷方式也可以被拖拽到桌面单独放置, 变成单独的桌面快捷方式。
在 script
中引入组件
const shortcut = uni.requireNativePlugin('Ba-Shortcut')
可在App.vue中快速集成,创建在onLauncher和onShow都可,点击事件在onShow中监听
<script> const shortcut = uni.requireNativePlugin('Ba-Shortcut') export default { onLaunch: function() { console.log('App Launch') //创建快捷方式 shortcut.create({ shortcutId: "MyCamera",//快捷方式id shortLabel: "随手拍",//快捷方式显示短文本 longLabel: "随时随地,拍一拍",//快捷方式显示长文本 iconName: "ic_camera",//快捷方式图标资源名称,参照‘UI 图标设置’ }, (res) => { console.log(res); }); }, onShow: function() { console.log('App Show') //快捷方式点击事件监听 var args = plus.runtime.arguments; if (args) { if(args.shortcutId){ //args参数如:{"shortLabel":"随手拍","shortcutId":"MyCamera"} //根据快捷方式的 shortcutId 判断 //这里写你的处理逻辑 } console.log(args); } }, onHide: function() { console.log('App Hide') } } </script>
可在页面 script
中调用(示例参考,可根据自己业务和调用方法自行修改)
data() { return { shortcutId: "MyCamera", shortLabel: "随手拍", longLabel: "随时随地,拍一拍", iconName: "ic_camera", } }, methods: { create() { //创建 shortcut.create({ shortcutId: this.shortcutId, shortLabel: this.shortLabel, longLabel: this.longLabel, iconName: this.iconName, }, (res) => { console.log(res); uni.showToast({ title: res.msg, icon: "none", duration: 3000 }) }); }, update() { //更新 shortcut.update({ shortcutId: this.shortcutId, shortLabel: this.shortLabel, longLabel: this.longLabel, }, (res) => { console.log(res); uni.showToast({ title: res.msg, icon: "none", duration: 3000 }) }); }, deleteS() { //删除 shortcut.delete({ shortcutId: this.shortcutId, }, (res) => { console.log(res); uni.showToast({ title: res.msg, icon: "none", duration: 3000 }) }); }, }
在应用生命周期app.vue的onLaunch事件中设置监听:
export default { ... onLaunch: function() { this.checkArguments(); // 重点是以下: 一定要监听后台恢复 !一定要 plus.globalEvent.addEventListener('newintent', (e) => { this.checkArguments(); // 检测启动参数 }); }, onShow: function() { }, onHide: function() { }, methods: { checkArguments() { var args = plus.runtime.arguments; if (args) { console.log(args); let args1 = JSON.parse(args); if(args1.shortcutId){ //args参数如:{"shortLabel":"随手拍","shortcutId":"MyCamera"} //根据快捷方式的 shortcutId 判断 //这里写你的处理逻辑 } // 处理args参数,如直达到某新页面等 } }, } ... }
名称 | 说明 |
---|---|
create | 创建快捷方式 |
update | 更新快捷方式,也可以用create重建更新 |
delete | 删除快捷方式 |
创建快捷方式
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
shortcutId | String | true | ‘’ | 快捷方式id |
shortLabel | String | true | ‘’ | 快捷方式显示短文本 |
longLabel | String | true | ‘’ | 快捷方式显示长文本 |
iconName | String | true | ‘’ | 快捷方式图标资源名称,参照‘UI 图标设置’ |
更新快捷方式
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
shortcutId | String | true | ‘’ | 快捷方式id |
shortLabel | String | true | ‘’ | 快捷方式显示短文本 |
longLabel | String | true | ‘’ | 快捷方式显示长文本 |
删除快捷方式
属性名 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
shortcutId | String | true | ‘’ | 快捷方式id |
应用消息通知插件(多种样式,新增支持常驻通知模式) Ba-Notify(文档)
应用未读角标插件 Ba-Shortcut-Badge (文档)
扫码原生插件(毫秒级、支持多码)Ba-Scanner-G(文档)
扫码原生插件 - 新(可任意自定义界面版本;支持连续扫码;支持设置扫码格式)Ba-Scanner(文档)
动态修改状态栏、导航栏背景色、字体颜色插件 Ba-AppBar(文档)
安卓保活插件(采用多种主流技术) Ba-KeepAlive(文档)
安卓快捷方式(桌面长按app图标) Ba-Shortcut(文档)
自定义图片水印(任意位置) Ba-Watermark(文档)
最接近微信的图片压缩插件 Ba-ImageCompressor(文档)
视频压缩、视频剪辑插件 Ba-VideoCompressor(文档)
动态切换应用图标、名称(如新年、国庆等) Ba-ChangeIcon(文档)
原生Toast弹窗提示(穿透所有界面、穿透原生;自定义颜色、图标 ) Ba-Toast(文档)
websocket原生服务(自动重连、心跳检测) Ba-Websocket(文档)
智能安装(自动升级) Ba-SmartUpgrade(文档)
监听通知栏消息(支持白名单、黑名单、过滤) Ba-NotifyListener(文档)
全局置灰、哀悼置灰(可动态、同时支持nvue、vue) Ba-Gray(文档)
获取设备唯一标识(OAID、AAID、IMEI等) Ba-IdCode(文档)
实时定位(系统、后台运行、支持息屏)插件 Ba-Location(文档)
实时定位(高德、后台运行、支持息屏、坐标转换、距离计算) Ba-LocationAMap(文档)
窗口小工具、桌面小部件、微件 Ba-AppWidget(文档)
窗口小工具、桌面小部件、微件(日历、时间) Ba-AwCalendarS(文档)
悬浮窗(在其他应用上层显示) Ba-FloatWindow(文档)
悬浮窗(应用内、无需授权) Ba-FloatWindow2(文档)
悬浮窗(悬浮球、动态菜单、在其他应用上层显示) Ba-FloatBall(文档)
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。