从资产设置壁纸 [英] setting wallpaper from assets

查看:163
本文介绍了从资产设置壁纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图从资产设置壁纸它需要时间来完成这项工作,所以也许有更简单的方法,而不是我的硬盘code

when i try to set Wallpaper from Assets it takes time to get the job done so maybe there is easier way instead of my hardcode

public void Setwallpaper(int position , Context context) throws IOException{    
    AssetManager am = mContext.getAssets();
    nlist = am.list("Gallary");
     BufferedInputStream buf = new BufferedInputStream(am.open(nlist[position]));
     bitmap = BitmapFactory.decodeStream(buf);

     buf.close();
    WallpaperManager myWallpaperManager = WallpaperManager
            .getInstance(context);
    try {
        myWallpaperManager.setBitmap(bitmap);
        Toast.makeText(context, "Wallpaper set",
                0).show();
    } catch (IOException e) {
        Toast.makeText(context,
                "Error setting wallpaper", Toast.LENGTH_SHORT)
                .show();
    }
}

它需要大约3秒这样做,而我所看到的其他应用程序都能够做到这一点,在不到一秒钟的任何建议,我将AP preciate它感谢

it takes about 3 secs to do it while i have seen other applications were able to do it in less than a sec any suggestion i will appreciate it thanks

推荐答案

试试这个

   WallpaperManager myWallpaperManager =WallpaperManager.getInstance(getApplicationContext());
    InputStream ims = getAssets().open("yourimage.jpg");
    myWallpapaerManager.setStream(ims)

这篇关于从资产设置壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆