uni-app设置android的锁屏壁纸(android.app.WallpaperManager)。。。

还是有个问题,壁纸在华为note8上面显示大图片,导致只能显示一部分啊。搞不动。锁屏壁纸正常。

            setting() {
                //uni.showToast({
                //  icon: 'none',
                //  title: '正在设为壁纸'
                //})
                var that = this;
                setTimeout(() => {
                    var WallpaperManager = plus.android.importClass('android.app.WallpaperManager');
                    //console.log(WallpaperManager);
                    var Main = plus.android.runtimeMainActivity();
                    var wallpaperManager = WallpaperManager.getInstance(Main);
                    //console.log(wallpaperManager);
                    //var wpm = plus.android.importClass(wallpaperManager);
                    var BitmapFactory = plus.android.importClass('android.graphics.BitmapFactory');
                    //console.log(wpm);
                    //console.log(this.data[this.index]);
                    uni.showLoading({
                        title:'下载图片...'
                    })
                    
                    uni.downloadFile({
                        url: this.data[this.index],
                        complete: (e) => {
                            uni.hideLoading();
                        },
                        success: (e) => {
                            var filePath = e.tempFilePath.replace('file://', '');
                            //console.log(e.tempFilePath);
                            //console.log(filePath);
                            filePath = plus.io.convertLocalFileSystemURL(filePath);
                            //console.log(filePath);
                            var bitmap = BitmapFactory.decodeFile(filePath);
                            var h = plus.android.invoke(bitmap,"getHeight");//bitmap.getHeight(); 
                            var w = plus.android.invoke(bitmap,"getWidth");//bitmap.getWidth(); 
                            var h0 = h / plus.display.resolutionHeight;
                            var w0 = w / plus.display.resolutionWidth;
                            console.log(h ,w ,h0 ,w0,plus.display.resolutionHeight*plus.screen.scale ,plus.display.resolutionWidth*plus.screen.scale  );
                            //console.log(bitmap);
                            try {
                                //wallpaperManager.suggestDesiredDimensions(, );
                                wallpaperManager.setBitmap(bitmap);
                                wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK);  //设置锁屏
                                //var it = wallpaperManager.getCropAndSetWallpaperIntent(filePath);// (that.data[that.index])
                                //console.log(it);
                                uni.showToast({
                                    icon: 'none',
                                    title: '壁纸设置成功'
                                })
                            } catch (e) {
                                console.log(e);
                                uni.showToast({
                                    icon: 'none',
                                    title: '壁纸设置失败' + e
                                })
                            }
                        },
                        fail: () => {
                            uni.showToast({
                                icon: 'none',
                                title: '壁纸设置失败'
                            })
                        }
                    })
                }, 100)
            },

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券