setting wallpaper from assets

早过忘川 提交于 2019-12-24 01:41:08

问题


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();
    }
}

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


回答1:


Try this

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



回答2:


Above example works, don't forget to add permission



来源:https://stackoverflow.com/questions/15437362/setting-wallpaper-from-assets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!