0

I am creating a wallpaper app for the android platform, and I have my XML set up perfectly, but I cannot figure out a good procedure to set the selected photo to the home screen/lock screen via button. Any input is appreciated greatly.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Solomon Reed
  • 31
  • 1
  • 1
  • 7
  • Please check this link, it's will help you: http://stackoverflow.com/questions/20053919/programmatically-set-android-phones-background – Hong Thai Sep 21 '15 at 06:41
  • here is a tutorial using the WallpaperManager -- http://android-er.blogspot.in/2011/03/set-wallpaper-using-wallpapermanager.html – Tasos Sep 21 '15 at 06:49

1 Answers1

0

Try this:

add this code in your Manifest.xml

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

and then you can set the background with this code:

Button buttonSetWallpaper = (Button)findViewById(R.id.set);
            ImageView imagePreview = (ImageView)findViewById(R.id.preview);
            imagePreview.setImageResource(R.drawable.five);

            buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
            @Override
            public void onClick(View arg0) {
            // TODO Auto-generated method stub
            WallpaperManager myWallpaperManager 
            = WallpaperManager.getInstance(getApplicationContext());
            try {
                myWallpaperManager.setResource(R.drawable.five);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            }});

it will work.