system wallpaper should change through service

2019-02-15 21:59发布

问题:

my application requires a service that changes the system wallpaper in a particular time interval how should I implement this, please help???

回答1:

Create your service class

class WallpaperService extends IntentService {

    @Override
    protected void onHandleIntent(Intent intent) {
        Timer progressTimer = new Timer();
        timeTask = new ProgressTimerTask();
        progressTimer.scheduleAtFixedRate(timeTask, 0, 1000);
    }

    private class ProgressTimerTask extends TimerTask {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    int currenMinutes = 0; // set your time here
                    changeWallpapers(currentMinutes);
                }
            });
        }
    }

    private void changeWallpapers(int minutes) {
        if(minutes == 1)
            layout.setBackGround(Color.RED);
        if(minutes == 2)
            layout.setBackGround(Color.BLUE);
    }
}

}

And then call your service Intent where your want



回答2:

Well, I have implemented this function. I register an Alarm in the system and connect it to a BroadcastReceiver. When the BroadcastReceiver is triggered, in the OnReceive() method, you can set a wallpaper for the system.