mgy最新地址 mgyuser.com

最近在做一款壁纸app,刚接触native.js,因为对安卓也不熟悉,直到google了下才找到了设置 锁屏壁纸的方法,桌面壁纸方法官网社区也是有答案的。

As of the latest Android API 24 it is possible to update the Lockscreen wallpaper by using the WallpaperManager and providing the FLAG_LOCK flag.

wallpaperManager.setBitmap(bitmap); //设置壁纸
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK); //设置锁屏

通过native.js修改系统壁纸和锁屏壁纸,整合的源码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//设置壁纸和锁屏
function setwallpaper($wallpaper_url){
    var WallpaperManager = plus.android.importClass("android.app.WallpaperManager");
    //获取应用主activity实例对象
    var Main = plus.android.runtimeMainActivity();
    var wallpaperManager = WallpaperManager.getInstance(Main);
    plus.android.importClass(wallpaperManager);
    var BitmapFactory = plus.android.importClass("android.graphics.BitmapFactory");
    var url=$wallpaper_url;  // 换成要设置的壁纸图片路径
    
    //将本地URL路径转换成平台绝对路径,如url为“_doc/a.png”
    var path=plus.io.convertLocalFileSystemURL(url);
    //解析图片文件并创建对应的Bitmap对象
    var bitmap = BitmapFactory.decodeFile(path);
    try{
        wallpaperManager.setBitmap(bitmap);  //设置壁纸
        wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK);  //设置锁屏

       
      
        bitmap.recycle()// 设置完毕桌面要进行 原生层的BITMAP回收 减少内存压力
        
    }catch(e){
        //TODO handle the exception
    }
}

Bcoder资源网 » 使用native.js修改系统壁纸和锁屏壁纸(Android)

免费支持本站,谢谢大家!

转载于:https://www.cnblogs.com/mgyuser/p/11084351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值