After uniapp packs Android, it can be automatically started on the Android screen and in the state of no network, without affecting the display of data;
Realize boot self-starting (using plug-ins)
Android self-starting plug-in address
Instructions
Select the project you want to start automatically
Write the following code under app-plus in the project's manifest.json
Note that you need to replace android_package_name with your own, otherwise you cannot package Android apk
"nativePlugins" : {
"Fvv-AutoStart" : {
"__plugin_info__" : {
"name" : "安卓开机自启动 Fvv-AutoStart",
"description" : "uni-app 安卓开机自启动插件,不保证所有机型和系统都有效",
"platforms" : "Android",
"url" : "https://ext.dcloud.net.cn/plugin?id=1820",
"android_package_name" : "写自己的",
"ios_bundle_id" : "",
"isCloud" : true,
"bought" : 1,
"pid" : "1820",
"parameters" : {
}
}
}
}
Then turn on this option in the app permission configuration
, and after packaging, Android can be started automatically on Android.
Realize the display of data without affecting the state of no network
onLoad() {
this.loadData();
},
// methods 下
loadData() {
uni.getNetworkType({
success: (res) => {
console.log(res)
if (res.networkType === 'none') {
// 无网络连接,从本地缓存中读取数据
const data = uni.getStorageSync('listData')
if (data) {
this.listData = data
}
} else {
// 有网络连接,通过网络请求获取数据
uni.request({
url: 'https://xxx.com/list',
success: (res) => {
this.listData = res.data
// 将数据保存到本地缓存中
uni.setStorageSync('listData', res.data)
}
})
}
}
})
}
Thank you all for supporting me!