Reputation: 47
I want to set the image as wallpaper of the device by clicking on a button,
I set the click listener (setWall) but the image is not scaled to the device's display.
imageBrought = getIntent().getExtras().getString("appMomentImage");
Glide.with(getApplicationContext()).load(imageBrought).dontAnimate().into(imagePreview);
setWall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Glide.with(getApplicationContext()).load(imageBrought).asBitmap().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
try {
WallpaperManager.getInstance(getApplicationContext()).setBitmap(resource);
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), "Your Wallpaper Has Been Set!", Toast.LENGTH_LONG).show();
}
});
}
});
Upvotes: 1
Views: 33
Reputation: 13129
You can get your device metrics with this and then just pass to your image that size
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.heightPixels;
metrics.widthPixels;
Upvotes: 1