1

Good morning I have a code that works right to set wallpapers which was downloaded from net at a size of 1024 x 768 in jpg when I set a wallpaper, this is distributed to all homescreens but from android 4+ they are not scrollable, putting a part of the image fixed for all homescreens I would like to solve the problem so I hope you could help me

greetings and sorry for me english

//path is a String with image's url
public int setWallpaper(String path) {          
    int width, height;
    Bitmap dbm, bm;         
    bm = null;
    dbm = null; 
    InputStream is = null;

    WallpaperManager wpm = wallpaperManager.getInstance(this);              

    //all images are 1024x 768 
    //to scale bitmap the widht have to be 1.33 bigger than screen's height
    if((wpm != null) && (dis != null)){ 
        height = dis.getHeight();
        width = (int) (height * 1.33);              

        try {           
            URLConnection conn = new URL(path).openConnection();                
            conn.connect();             
            is = conn.getInputStream();                 

            if (is != null) {                   
                bm = BitmapFactory.decodeStream(new FlushedInputStream(is));                    
                dbm = Bitmap.createScaledBitmap(bm, width, height, false);                  
                wpm.setBitmap(dbm); 

            }else {
                return 2;
            }

        } catch (MalformedURLException e) {                 
            e.printStackTrace();                
        } catch (IOException e) {               
            e.printStackTrace();                
        } finally {             
            if (is != null) {
                try {
                    is.close();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }           
        if(bm != null){
            bm.recycle();
        }
        if(dbm != null){
            dbm.recycle();  
        }           
    }else {
        return 1;
    }
    return 0;
}

1 Answers1

1

They are no longer scrollable on android 4, however, to avoid them being zoomed in, you can do the following:

// get screen dimensions
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;

wpm.suggestDesiredDimensions(width, height);
wpm.setBitmap(dbm);

By using suggestDesiredDimensions you specify the size of the wallpaper.

From the developer reference:

public void suggestDesiredDimensions (int minimumWidth, int minimumHeight)

Since: API Level 5 For use only by the current home application, to specify the size of wallpaper it would like to use. This allows such applications to have a virtual wallpaper that is larger than the physical screen, matching the size of their workspace.

Note developers, who don't seem to be reading this. This is for home screens to tell what size wallpaper they would like. Nobody else should be calling this! Certainly not other non-home-screen apps that change the wallpaper. Those apps are supposed to retrieve the suggested size so they can construct a wallpaper that matches it.

Remember you will also need to request the SET_WALLPAPER_HINTS permission on your manifest by doing:

<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
  • I'm looking for a solution to put the wallpaper shared among all homescreens Your response does not reflect any changes, the wallpaper continues fix with the same part of image to all homescreens – user1990408 Jan 28 '13 at 16:56