Android - how to set the wallpaper image

Is it possible to set the android wallpaper image programatically? I'd like to create a service that downloads an image from the web and updates the home screen wallpaper periodically.


Asked by: Maya894 | Posted: 24-01-2022






Answer 1

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);

In your manifest file:

<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>

Answered by: Blake204 | Posted: 25-02-2022



Answer 2

From this page on the developer site:

public void setStream (InputStream data)

Change the current system wallpaper to a specific byte stream. The give InputStream is copied into persistent storage and will now be used as the wallpaper. Currently it must be either a JPEG or PNG image.

Answered by: Emma453 | Posted: 25-02-2022



Answer 3

If you have bitmap of image than you will add this function to set as wallpaper:

  public void SetBackground(int Url) {

    try {
        File file = new File("/sdcard/sampleimage");
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), Url);
        bitmap.compress(CompressFormat.JPEG, 80, new FileOutputStream(file));
        Context context = this.getBaseContext();
        context.setWallpaper(bitmap);            
        Toast.makeText(getApplicationContext(), "Wallpaper has been set",             Toast.LENGTH_SHORT).show();            
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }         
}

you should add permission for this

<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>

hope it will work

Answered by: Grace334 | Posted: 25-02-2022



Answer 4

OK Here's how to do it before api 2.0:

You need to call getApplicationContext.setWallpaper() and pass it the bitmap.

This method is now deprecated. See ChrisF's answer for details on the new method.

Answered by: Dominik531 | Posted: 25-02-2022



Similar questions

android - save image from web server and set it as wallpaper

Can anyone please provide me some idea/guidance on how to save an image from a webserver and set it as wallpaper? i am developing an android application which needs to do that and i am new in android. Thanks a lot. I had tried writing my own code but it doesn't work as i can't find my images after download but the wallpaper has change to the downloaded picture. here is my existing code. Bitmap bmImg...


android - save image from web server and set it as wallpaper

Can anyone please provide me some idea/guidance on how to save an image from a webserver and set it as wallpaper? i am developing an android application which needs to do that and i am new in android. Thanks a lot. I had tried writing my own code but it doesn't work as i can't find my images after download but the wallpaper has change to the downloaded picture. here is my existing code. Bitmap bmImg...


How to set wallpaper in Android

I am using Android SDK 1.6. Could someone tell me how to set an image as the wallpaper in the homescreen. getApplicationContext().setWallpaper(); seems to be not working for me.


Android Live Wallpaper touch events

I've just started with Android, I'm making a simple Live wallpaper. I'm testing it on a 2.1 emulator. The trouble is while it works in the preview screen before you choose "Set Wallpaper" the touch events don't appear to register on the screen once you've selected it as a wallpaper. Do I need to state anything in the manifest about touch events or so to get it to work? Little bit confused why it would work in one and not t...


android - setting wallpaper through code

I was trying to make an app which also had the facility to let user select wallpaper he would like to set. I have managed this by calling the Gallery Intent. Once the user selects a specific image, the data path of the image is returned to me which then i preview to the user by setting the image onto an imageview. The problem crops up when the image size (and/or resolution) is greater than what android expects. Thi...


java - Cropping a wallpaper in order to have a crisp image

I am currently working on a wallpaper application. Is there a way to make a bitmap look less blurry and more crisp once it is set as a wallpaper? Does it just require cropping the picture and resizing it to fit the size of the screen perfectly, or there is some other way? P.S. I read that the application wallpaper set and save is able to deliver very good quality wallpapers once launched!


How to set wallpaper in Android?

This question already has answers here:


Set video as wallpaper on Android

I want to know how to set Video as wallpaper or it is not possioble. I can set image as wallpaper and I can build live wallpaper but I can't set video as wallpaper ? so anyone has an idea how can I do that ? Thanks in Advance.


gallery - 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...


java - "Set wallpaper" button function, Android

I've created a custom gallery; however, the "Set wallpaper" button will not set the wallpaper. Here's the wallpaper.java I have. I'm just lost on how to implement OnClickListener and then set my button to use an onclicklistener like so: buttonName.setOnClickListener(this); package com.totem; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.L...


java - Live wallpaper animation force closing when I add more than 10 frames?

I'm trying to make a simple livewallpaper out of a series of boot animation .pngs... I'm using private static final int NUM_RES = 9; private final Bitmap[] mPics = new Bitmap[NUM_RES]; CubeEngine() { Resources res = getResources(); for (int i = 0; i&lt; NUM_RES; i++) { int id = res.getIdentifier("boot_0010" + (i + 1), "drawable", "minghai.wall...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top