uniapp 安卓快捷方式插件(桌面长按app图标) Ba-Shortcut
簡介(下載地址)
Ba-Shortcut 是一款App Shortcuts(安卓快捷方式)插件。Shortcuts是指在桌面長按app圖標而出現的快捷方式, 可以為你的app的關鍵功能添加更快速的入口而不用先打開app,點擊快捷方式可以訪問應用功能, 并且這種快捷方式也可以被拖拽到桌面單獨放置, 變成單獨的桌面快捷方式。
- 支持創建多個快捷方式
- 支持自定義圖標
- 支持設置長文本和短文本(優先顯示長文本,空間不夠時自動顯示短文本)
- 支持創建、更新、刪除
- 應用添加App Shortcuts是Android 7.1(API 25)的API, 所以只能在Android 7.1的設備上顯示, 同時需要launcher支持, 比如Pixel launcher(Pixel設備的默認launcher), Now launcher(Nexus設備上的launcher)現在就支持, 其他launcher也可以提供支持.
效果展示
使用方法
引用
在 script 中引入組件
const shortcut = uni.requireNativePlugin('Ba-Shortcut')示例1(App.vue)
可在App.vue中快速集成,創建在onLauncher和onShow都可,點擊事件在onShow中監聽
<script>const shortcut = uni.requireNativePlugin('Ba-Shortcut')export default {onLaunch: function() {console.log('App Launch')//創建快捷方式shortcut.create({shortcutId: "MyCamera",//快捷方式idshortLabel: "隨手拍",//快捷方式顯示短文本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>示例2(頁面)
可在頁面 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})});},}UI 圖標設置
- 快捷方式圖標:在項目的 “nativeplugins\Ba-Shortcut\android\res\drawable” 目錄下(沒有就新建),任意添加圖片(支持png、jpg、xml矢量圖),名字在 create 方法的 “iconName”字段設置即可。如添加自定義圖片"ic_camera.png",那么設置 iconName 為 “ic_camera”。注意:更改后需要重新制作基座才能生效,建議提前配置。
快捷方式點擊事件監聽
在應用生命周期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 | 刪除快捷方式 |
create 方法參數
創建快捷方式
| shortcutId | String | true | ‘’ | 快捷方式id |
| shortLabel | String | true | ‘’ | 快捷方式顯示短文本 |
| longLabel | String | true | ‘’ | 快捷方式顯示長文本 |
| iconName | String | true | ‘’ | 快捷方式圖標資源名稱,參照‘UI 圖標設置’ |
update 方法參數
更新快捷方式
| shortcutId | String | true | ‘’ | 快捷方式id |
| shortLabel | String | true | ‘’ | 快捷方式顯示短文本 |
| longLabel | String | true | ‘’ | 快捷方式顯示長文本 |
delete 方法參數
刪除快捷方式
| shortcutId | String | true | ‘’ | 快捷方式id |
系列插件
圖片選擇插件 Ba-MediaPicker (文檔)
圖片編輯插件 Ba-ImageEditor (文檔)
文件選擇插件 Ba-FilePicker (文檔)
應用消息通知插件 Ba-Notify(文檔)
應用未讀角標插件 Ba-Shortcut-Badge (文檔)
應用開機自啟插件 Ba-Autoboot(文檔)
掃碼原生插件(毫秒級、支持多碼)Ba-Scanner-G(文檔)
掃碼原生插件 - 新(可任意自定義界面版本;支持連續掃碼;支持設置掃碼格式)Ba-Scanner(文檔)
動態修改狀態欄、導航欄背景色、字體顏色插件 Ba-AppBar(文檔)
原生sqlite本地數據庫管理 Ba-Sqlite(文檔)
安卓保活插件(采用多種主流技術) Ba-KeepAlive(文檔)
安卓快捷方式(桌面長按app圖標) Ba-Shortcut(文檔)
自定義圖片水印(任意位置) Ba-Watermark(文檔)
最接近微信的圖片壓縮插件 Ba-ImageCompressor(文檔)
視頻壓縮、視頻剪輯插件 Ba-VideoCompressor(文檔)
動態切換應用圖標、名稱(如新年、國慶等) Ba-ChangeIcon(文檔)
原生Toast彈窗提示(穿透所有界面、穿透原生;自定義顏色、圖標 ) Ba-Toast(文檔)
圖片涂鴉、畫筆 Ba-ImagePaint(文檔)
pdf閱讀(手勢縮放、顯示頁數) Ba-Pdf(文檔)
聲音提示、震動提示、語音播報 Ba-Beep(文檔)
websocket原生服務(自動重連、心跳檢測) Ba-Websocket(文檔)
總結
以上是生活随笔為你收集整理的uniapp 安卓快捷方式插件(桌面长按app图标) Ba-Shortcut的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用RamDiskNT虚拟软盘后vmwa
- 下一篇: android 搜狗地图包名,搜狗地图