Change Image Background of the Android System

1

What I am trying to do is to have an application where there is a button, when I press the button I want to change the Background image of the Android system .

I want to change this image:

I have researched how I can do this, but the only thing is:

  • How to change the image of an ImageView.
  • How to change the background image of an Application.
  • How to change the image of an Activity ... and things like that.

Obviously I'm looking bad, What can I do to achieve my goal ???

Thanks in advance.

    
asked by ELM 25.12.2017 в 16:34
source

1 answer

5

You can use the WallpaperManager class:

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

        WallpaperManager myWallpaperManager 
        = WallpaperManager.getInstance(getApplicationContext());
        try {
            myWallpaperManager.setResource(R.drawable.five);
        } catch (IOException e) {

            e.printStackTrace();
        }
    }
});

and you must add to your file AndroidManifest.xml the permission to make the change:

<uses-permission android:name="android.permission.SET_WALLPAPER"/>
    
answered by 25.12.2017 / 16:56
source