当我尝试从资产中设置壁纸时,完成工作需要时间,所以也许有更简单的方法而不是我的硬编码
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秒才能完成,而我看到其他应用程序能够在不到一秒的时间内完成任何建议我将非常感谢
答案 0 :(得分:2)
试试这个
WallpaperManager myWallpaperManager =WallpaperManager.getInstance(getApplicationContext());
InputStream ims = getAssets().open("yourimage.jpg");
myWallpapaerManager.setStream(ims)
答案 1 :(得分:0)
以上示例有效,请不要忘记添加权限