system wallpaper should change through service

后端 未结 2 744
日久生厌
日久生厌 2021-01-07 11:19

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

相关标签:
2条回答
  • 2021-01-07 11:38

    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

    0 讨论(0)
  • 2021-01-07 11:52

    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.

    0 讨论(0)
提交回复
热议问题