0

Hlo, can any one help me with this problem here. . I am getting confused using bitmap to set wallpaper . ... pls see the code here http://www.androidpeople.com/android-gallery-example

CodeZero
  • 3
  • 4
  • Check : http://stackoverflow.com/questions/26735180/crash-when-i-use-method-setwallpaper-android/26735713#26735713 – Haresh Chhelana Nov 08 '14 at 03:58
  • @CodeZero have u know how to pic image from gallery – Naveen Tamrakar Nov 08 '14 at 04:39
  • here I mean gallery as a collection of wallpapers in a apk... I know to set wallpaper only for one image everytime :( I used a button setOnClickListener and then inside it I used wallpaper manager for which I give resource as R.drawable.a_1. .. this sets only that image.ie. image a_1 – CodeZero Nov 08 '14 at 04:52

1 Answers1

0

I looked over the code you have shown and I don't think is the best solution, simply because is not resource friendly.You get an array of ints to hold your drawables and so on.All in all,I came up with a better solution,I guess.

I will give you only the important part of the code though cause I am in a hurry and I really don't have time to write it all, but if you need more info ,leave a comment and I will come back later on.

Drawable thephoto;

//Important note!!!
//YOU need to add a OnClickListener to each view you got going there.I just added a clickListener to a variable yourView that I didn't even declare because i don't know what you got there ,but yourView ,in this case, can be a button,imageView,imageButton and so on.
//If you need more help with this, comment and whenever I am back,later on,I will answer gladly.
yourView.setOnClickListener(new onClickListener(View v){
    @override
    onTouch(View v){
     thepohoto = v.getResources().getDrawable(); 
     //if this doesn't work, go like this: the photo = v.getBackground();
  }
})
//Now you have the photo of the item you clicked.So you just set it.

WallpaperManager myWall = WallpaperManager.getInstance(getApplicationContext());
 try {
    myWall.setResource(thephoto); // change here give the selected image here
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

All n all ,this has to work, if you understand the basics of it and you know where to add to code.

Vlad
  • 910
  • 1
  • 10
  • 18