2

当我尝试从资产设置墙纸时,完成工作需要时间所以也许有更简单的方法而不是我的硬代码

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 秒,而我已经看到其他应用程序能够在不到一秒的时间内完成它任何建议我将不胜感激谢谢

4

2 回答 2

2

尝试这个

   WallpaperManager myWallpaperManager =WallpaperManager.getInstance(getApplicationContext());
    InputStream ims = getAssets().open("yourimage.jpg");
    myWallpapaerManager.setStream(ims)
于 2013-03-15T16:29:02.987 回答
0

上面的例子有效,不要忘记添加权限

于 2013-06-25T06:05:48.803 回答