Reputation: 3946
I have currently been trying to set a background of my phone using an android wallpaper app that i made. However every time i press "Set background" it stretches the image.
Here is the code that i am using
btnSetWallpaper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
WallpaperManager wManager;
try {
// Bitmap bitmap = ((BitmapDrawable)imageView1.getDrawable()).getBitmap();
wManager = WallpaperManager.getInstance(view.getContext().getApplicationContext());
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int fullWidth = size.x;
int fullHeight = size.y;
//int fullWidth = wManager.getDesiredMinimumWidth();
//int fullHeight = wManager.getDesiredMinimumHeight();
Log.d("Debug", Integer.toString(fullWidth));
Log.d("Debug", Integer.toString(fullHeight));
Bitmap bitmapResized = Bitmap.createScaledBitmap(bmpWallpaper, fullWidth * 2, fullHeight, true);
wManager.setBitmap(bitmapResized);
} catch (IOException e) {
e.printStackTrace();
}
Core.makeNotification(view.getContext(), "MyNotification", "Your wallpaper has been set, enjoy!");
Core.makeAlert(view.getContext(), "Wallpaper set", "Your wallpaper has been set, enjoy!");
}
});
Upvotes: 2
Views: 971
Reputation: 3946
Okay after the comment from bakriOnFire i searched around on the link he gave me, after combining a bit of my code with the code described there i've found a solution!
btnSetWallpaper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
WallpaperManager wManager = WallpaperManager.getInstance(view.getContext());
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int fullWidth = size.x;
int fullHeight = size.y;
//int fullWidth = wManager.getDesiredMinimumWidth();
//int fullHeight = wManager.getDesiredMinimumHeight();
Log.d("Debug", Integer.toString(fullWidth));
Log.d("Debug", Integer.toString(fullHeight));
Bitmap bitmapResized = Bitmap.createScaledBitmap(bmpWallpaper, fullWidth, fullHeight, true);
wManager.suggestDesiredDimensions(bitmapResized.getWidth(), bitmapResized.getHeight());
wManager.setBitmap(bitmapResized);
} catch (IOException e) {
e.printStackTrace();
}
Core.makeNotification(view.getContext(), "MCPaper", "Your wallpaper has been set, enjoy!");
Core.makeAlert(view.getContext(), "Wallpaper set", "Your wallpaper has been set, enjoy!");
}
});
I really hope that in the future this well help people out because i've spend a long time on this. enjoy
Upvotes: 2