How can I change device Wallpaper after some time automatically?

167 Views Asked by At

I am setting the wallpaper with WallpaperManager, it works well when I set a single Wallpaper with the on-click button.

But the main feature is that: when a user enters time from AlertDialog then wallpaper should change after one, according to the user input time. When wallpaper list or array end then again start wallpaper from 1.

  1. First I get all the Path of wallpaper into ArrayList.
  2. Start for loop according to ArrayList length.
  3. When loop run first time, wallpaper set and I call Thread.Sleep(5*1000)
  4. In this way loop run second time after 5 sec and wallpaper change automatically.

So, Problem is that when the user enters the time from Alert Dialog

//Below is my code I write by hand, actual code is in project

for(int i = 0; i<listofWall.length; i++){
    Bitmap bitmap = here i get bitmap from ListOfWallpaper(i);
    WallpaperManager wm = WallpaperManager.getInstance(getContext());
    wm.setBitmap(bitmap);
    Thread.sleep(userEnterTimeInSec*1000);

    //I do below code for run loop again and again so that wallpaper change 
    after the end of wallpaper list

    if(i==listOfWall.length-1){
       i=0;
    }
}

So, when I run the application and enter the WallPaperTime into Alert Dialog and press the PositiveButton ("OK"), application user interface help and error comes on screen is ANR (Application Not Responding).

I also work with AsynckTask but the same error, because of Thread.Sleep() run continuously. I also use TimeUnit.Second.Sleep but the same condition.

So, there is way or any method how can I change wallpaper automatically with after user input time.

Please share your code, I shall be very thankful to you

0

There are 0 best solutions below