After uniapp is packaged with Android, it can be automatically started on the Android screen and in the state of no network, without affecting the display of data;

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
insert image description here

Select the project you want to start automatically

insert image description here
Write the following code under app-plus in the project's manifest.json
insert image description here
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
insert image description here
, 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!

Guess you like

Origin blog.csdn.net/weixin_44255044/article/details/129814280