I just got into this problem on the line CreateScaledBitmap, I am trying to set this image as device's wallpaper and I need to scale this image to the device, thats why I am doing this method but unfortunately I cant fix this Bitmap width() error
setWall.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onClick(View view) {
Picasso.with(getApplicationContext()).load(imageBrought).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
int width = metrics.widthPixels;
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(AppMomentSelected.this);
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(width, height);
try {
wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
});