バックエンドサーバーに接続することでページを更新するタイミングバックグラウンドサービスは、ネットワークの再開、リフレッシュWebView、表示を復元する場合、検出を継続します。が、私はこの機能を実現したい
2)ネットワークがOKの場合、バックグラウンドサーバに新しいURLが指定されている場合はバックグラウンドサービスが検出され続け、現在のページがリフレッシュされます。
バックエンドサーバーに接続することでページを更新するタイミングバックグラウンドサービスは、ネットワークの再開、リフレッシュWebView、表示を復元する場合、検出を継続します。が、私はこの機能を実現したい
2)ネットワークがOKの場合、バックグラウンドサーバに新しいURLが指定されている場合はバックグラウンドサービスが検出され続け、現在のページがリフレッシュされます。
AlarmManagerとPendingIntentとともにブロードキャスト受信機を使用できます。あなたの希望の期間、アラームの繰り返しを設定し、その期間に保留中のインテントを発生させます。
public void scheduleAlarmForURLAutoUpdate() {
Long time = new GregorianCalendar().getTimeInMillis()+1000 * 60 * 60 * 24;// current time + 24 Hrs
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent intentAlarm = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 1000 * 60 * 60 * 24, intentAlarm);// 24 Hrs
//Toast.makeText(this, "Alarm Scheduled for 24 Hrs", Toast.LENGTH_LONG).show();
}
AlarmReceiverクラス
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
updateURL(context);//Method to update the URL from the server and then refresh your WebView activity
}
パブリッククラスAlarmReceiverはBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Intent i = new Intent(context, AutoUpdateService.class);
context.startService(i);
}
}
を拡張し、私はまだ解決できないあなたのanswer.Butために本当に感謝していますこの質問。サーバーから新しいURLを取得した場合、どのようにWebViewを更新できますか?私は使う?ありがとう。 – JiangDelin