In this tutorial I will explain how to set Wallpaper.
To Set the Wallpaper we must declare following permission in manifest file
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
If you use an Image to set as wallpaper, The image may not fit to the Screen, it may be smaller or larger than the device screen, To overcome this problem or if we want that Image should to the screen for all the devices with different screen sizes, we need to use DisplayMatrics.
// get the Image to as Bitmap
Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.image));
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// get the height and width of screen
int height = metrics.heightPixels;
int width = metrics.widthPixels;
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {
wallpaperManager.setBitmap(bitmap);
wallpaperManager.suggestDesiredDimensions(width, height);
Toast.makeText(this, "Wallpaper Set", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
To Set the Wallpaper we must declare following permission in manifest file
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
If you use an Image to set as wallpaper, The image may not fit to the Screen, it may be smaller or larger than the device screen, To overcome this problem or if we want that Image should to the screen for all the devices with different screen sizes, we need to use DisplayMatrics.
// get the Image to as Bitmap
Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.image));
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// get the height and width of screen
int height = metrics.heightPixels;
int width = metrics.widthPixels;
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {
wallpaperManager.setBitmap(bitmap);
wallpaperManager.suggestDesiredDimensions(width, height);
Toast.makeText(this, "Wallpaper Set", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
hii
ReplyDeletethank's for this code it's work but when i set my image as wallpaper..it's perfect but in just one second it becomes zoomed and stretched..
plzz give me solution
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work sfondi disegni grafici
ReplyDeleteSome truly nice stuff on this site, I love it. macbook device template
ReplyDeleteKeep websiteing stuff like this I actually am fond of it device mockups
ReplyDeleteHey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates. abstract background blue
ReplyDeleteThis is something I actually have to try and do a lot of analysis into, thanks for the post background blue abstract
ReplyDeletehello!! Very interesting discussion glad that I came across such informative post. Keep up the good work friend. Glad to be part of your net community. logo design for startups
ReplyDeleteI felt very satisfied even as studying this web page. This became simply very informative web site for me. I clearly appreciated it. This become truly a cordial submit. thank you lots!. logo design for startups
ReplyDeleteI was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. papel de parede para quarto
ReplyDeletehello!! Very interesting discussion glad that I came across such informative post. Keep up the good work friend. Glad to be part of your net community. logo design agency
ReplyDeleteAivivu chuyên vé máy bay, tham khảo
ReplyDeletemua ve may bay di my
chuyen bay tu my ve vietnam
giá vé máy bay từ anh về việt nam
vé máy bay từ pháp về việt nam giá rẻ
chuyến bay thương mại từ nhật về việt nam
dat ve may bay tu han quoc ve viet nam
educator, Sue. Although Sue had a list of discharge instructions in her hand, she paused and High-return investment
ReplyDeleteeducator, Sue. Although Sue had a list of discharge instructions in her hand, she paused and führerschein kaufen erfahrungen
ReplyDeleteeducator, Sue. Although Sue had a list of discharge instructions in her hand, she paused and Online stock calculator
ReplyDeleteI’ll create a hyperlink to the web page about my personal weblog. ufaxs
ReplyDeleteI’ll create a hyperlink to the web page about my personal weblog. รีวิวเว็บพนันUFABET
ReplyDeleteI’ll create a hyperlink to the web page about my personal weblog. รีวิวคาสิโนออนไลน์
ReplyDeleteeducator, Sue. Although Sue had a list of discharge instructions in her hand, she paused and https://dealgamings.com/
ReplyDeleteI am constantly browsing online for ideas that can benefit me. Thanks! รีวิวUFABET
ReplyDeleteI’ll create a hyperlink to the web page about my personal weblog. https://site-7327699-9720-99.mystrikingly.com
ReplyDeleteI came to the exact conclusion as well some time ago. Great write-up and I will be sure to look back later for more news. million songs
ReplyDelete