当我尝试从资源中设置壁纸时,完成工作需要时间,所以也许有更简单的方法而不是我的硬编码
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 秒才能完成此操作,而我看到其他应用程序能够在不到一秒的时间内完成此操作,如有任何建议,我将不胜感激,谢谢
最佳答案
试试这个
WallpaperManager myWallpaperManager =WallpaperManager.getInstance(getApplicationContext());
InputStream ims = getAssets().open("yourimage.jpg");
myWallpapaerManager.setStream(ims)
关于android - 从资源中设置壁纸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15437362/