希望能够帮到你
setting() {
let url = 'https://ask.dcloud.net.cn/static/images/side/ask_zp_20230710.png';
// #ifdef APP-PLUS
let WallpaperManager = plus.android.importClass("android.app.WallpaperManager");
let Main = plus.android.runtimeMainActivity();
let wallpaperManager = WallpaperManager.getInstance(Main);
plus.android.importClass(wallpaperManager);
let BitmapFactory = plus.android.importClass("android.graphics.BitmapFactory");
uni.showLoading({
title: '下载图片...',
mask: true
});
uni.downloadFile({
url: url,
success: res => {
let filePath = res.tempFilePath.replace('file://', '');
filePath = plus.io.convertLocalFileSystemURL(filePath);
let bitmap = BitmapFactory.decodeFile(filePath);
try {
wallpaperManager.setBitmap(bitmap); //设置壁纸
uni.showToast({
icon: 'none',
title: '壁纸设置成功'
});
} catch (e) {
// console.log(e,'err');
uni.showToast({
icon: 'none',
title: '壁纸设置失败'
})
}
},
fail: err => {
uni.showToast({
icon: 'none',
title: '壁纸设置失败'
})
},
complete: () => {
uni.hideLoading();
}
});
// #endif
// #ifdef H5
uni.showToast({
icon: 'none',
title: '请在APP设置'
});
// #endif
}
1 个回复
喜欢技术的前端 - QQ---445849201
希望能够帮到你