system wallpaper should change through service

橙三吉。 提交于 2019-12-01 02:00:59
Yahor10

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!