创道夫
创道夫
  • 发布:2021-07-20 17:49
  • 更新:2021-07-20 17:52
  • 阅读:1548

小米手机设置锁屏壁纸不生效 wallpaperManager.setBitmap

分类:Native.js

暂时发现小米K30和k40手机设置锁屏没有用,运行真机也不报错
vivo、oppo、华为的手机正常

url = 'https://qimg.chydof.cn/20210720103107801027353.jpg';  

setwallpaper(url){  
                // #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);  
                        // let h = plus.android.invoke(bitmap,"getHeight");//bitmap.getHeight();   
                        // let w = plus.android.invoke(bitmap,"getWidth");//bitmap.getWidth();   
                        // let h0 = h / plus.display.resolutionHeight;  
                        // let w0 = w / plus.display.resolutionWidth;  
                        // console.log(h ,w ,h0 ,w0,plus.display.resolutionHeight*plus.screen.scale ,plus.display.resolutionWidth*plus.screen.scale  );  
                        try{  
                            // wallpaperManager.setBitmap(bitmap); //设置壁纸  
                            wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK);  //设置锁屏  
                            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  
            },
2021-07-20 17:49 负责人:无 分享
已邀请:
创道夫

创道夫 (作者) - 创意+DAO+夫子

@DCloud_App_Array @DCloud_Android_zl @DCloud_Android_DQQ 小米手机设置锁屏壁纸不生效怎么处理啊?

该问题目前已经被锁定, 无法添加新回复