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)
            },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章