问题
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