How to set android wallpaper
I am wondering if someone can help. I would like to create a simple wallpaper test app. I have tried a few things with no success. Eventually, I started playing with gallery codes and have a few achievements. But ... I am not sure how to attach a wallpaper function to the gallery. I am new to all this (I am only a few months into learning Droid apps with eclipse) is there someplace where I can find complete Java coding and possibly the XML file开发者_如何学Cs for a working wallpaper? I cannot build from scratch but I am getting better reading the source code creating buttons etc.
Another option is how can I insert a save as wallpaper function to the working gallery I have? I am assuming I can set a long press function but I am not sure how to go about that either. I do have a tutorial for creating long presses but I am not sure about the proper Java setup to accompany this.
Any help will be appreciated. Keep in mind I am new to both Java and Android coding. In other words keep it as simple as possible please. Or if someone has a simple wallpaper app and they don't mind sharing the source code ... that would help immensely.
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
System.out.println("Hi I am try to open Bit map");
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);
................................................. if you have image URI then use this
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
.............. Let me know if there is any issue .
If you have image URL then use
WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);
If you have image URI then use
WallpaperManager wpm = WallpaperManager.getInstance(context);
wpm.setResource(Uri.of.image);
If you want to use wallpaper as your app's background, then you have to use Wallpaper theme & call the Intent.Action_Set_Wallpaper to pick wallpaper.
public void onCreate(Bundle savedInstanceState) {
Activity.this.setTheme(android.R.style.Theme_Wallpaper);
super.onCreate(savedInstanceState);
setContentView(/*some layout*/);
}
//on button click
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
精彩评论