5

I am trying to change the current user wallpaper. I have set the set_wallpaper permission and it works. But when I change the wallpaper I have to wait about 15 seconds to see the wallpaper change.

This is currious because if I check the lock screen it has already changed.

Here is my code:

 public static void setWallpaper(final Context context, final Bitmap image){
        Thread thread = new Thread() {
            @Override
            public void run() {
                WallpaperManager wallpaperManager = WallpaperManager.getInstance(context.getApplicationContext());
                try {
                    if(image != null){
                        wallpaperManager.setBitmap(image);
                    }
                } catch (IOException ignored) {}
            }
        };

        thread.start();
}

I'm on Android 6. Any help would be appreciated.

Ananta
  • 660
  • 1
  • 7
  • 19
  • What is this method "refreshWallpaper(Context)" ? – Arthur Attout Feb 07 '18 at 13:08
  • It was a test, to force the wallpaper to refresh, I read that on a forum. But do not take care of it. I have tried with and without that method and the result is the same. – Ananta Feb 07 '18 at 13:36
  • See this, you already has a Refresh function, but maybe it can make work better https://stackoverflow.com/a/22932875/3117650 – Canato Feb 07 '18 at 13:38
  • Thanks for your response, I will try it and tell you if it works. But it looks very similar to my function (refreshWallpaper) : https://github.com/jess-bart/PictoThemo/blob/master/app/src/main/java/com/jessy_barthelemy/pictothemo/Helpers/ApplicationHelper.java – Ananta Feb 07 '18 at 13:50

2 Answers2

0

Why you used a Thread for this purpose?

Remove that and use your code directly on MainThread and see your code works correctly and instantly changed user wallpaper!

Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45
-1

It might be worth having a deeper look at the WallpaperManagers setBitmap method and the inner callback (ln 1055, ln 1713) ref

I am not entirely sure how this whole code works nor do I think this really helps you solving the problem but it might give you a hint.

See this question for a similar problem

redead
  • 360
  • 3
  • 16