Nicco
Nicco

Reputation: 47

Wallpaper not scaled to the device's display

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

Answers (1)

Gast&#243;n Saill&#233;n
Gast&#243;n Saill&#233;n

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

Related Questions