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