开发者

How to retrieve items from server after fixed time period?

I am returning 7 URL's that I retrieve from a Text document on a remote server.

The URL's are links to images that I want to then download and put into a cache. These URL's will change every week.

I want to retrieve these URL's from the text document开发者_Python百科 only once on a fixed day of week (e.g. Monday only).

How I can do that?


1: Make a service that connect server and get URL's then write URL to a file for use in you application. 2: Then Use alarm manger to create a alarm for a specif day. You can find details here.

how do I set an alarm manager to fire after specific days of week

While creating alarm you have to add your service with your alarm object so that when alarm time come. Then it run the service.(But be careful In that time there may be no internet.)

you can add your service to alarm object e.g

        /* Scheduling Alarm for URL's update service to run at One */
        Log.i(TAG, "Alarm started");
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.SECOND, 10);

        Intent versionUpdateService = new Intent(getApplicationContext(), MyURLUpdaterService.class);
        PendingIntent recurringUpdate = PendingIntent.getService(getApplicationContext(), 0, versionUpdateService,
                PendingIntent.FLAG_UPDATE_CURRENT);

        AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarms.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringUpdate);
        Log.i(TAG, "Alarm ended");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜