I'm using the picasso library for my app and it works very well so far. I have two activities, one which displays all the images and one that displays one image when I clicked on it in the first activity. The image is loaded into an imageView. Now I want to set the content of this imageView as my homescreen wallpaper. So far I have this:
if (id == R.id.set_wall) {
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.id.image);
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
try {
myWallpaperManager.setBitmap(mBitmap);
Toast.makeText(DetailActivity.this, "Wallpaper set",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(DetailActivity.this,
"Error setting wallpaper", Toast.LENGTH_SHORT)
.show();
}
return true;
}
But this gives me this error:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
Does anyone have an idea how I can set the content of this imageView as my wallpaper?
Thank you a lot!!