2016-09-29 2 views
-1

백 엔드 서버에 연결하여 페이지를 새로 고침 시간 초과 네트워크의 재개, webView 새로 고침, 디스플레이 복원, 오프 라인, 백그라운드 서비스가 감지를 계속합니다.내가이 기능을 달성 할

2) 네트워크가 정상이면 백그라운드 서버에 새 URL이 제공되면 백그라운드 서비스가 계속 감지되고 현재 페이지가 새로 고침됩니다.

답변

0

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 


} 
+0

내가 당신 answer.But 정말 감사 해요 브로드 캐스트 리시버 확장 이 질문. 서버에서 새 URL을 얻으면 웹 뷰를 새로 고칠 수 있습니까? 내가 사용합니까? 감사. – JiangDelin

0

공용 클래스 AlarmReceiver 난 아직도 해결할 수없는 {

@Override 
public void onReceive(Context context, Intent intent) 
{ 
    Intent i = new Intent(context, AutoUpdateService.class); 
    context.startService(i); 
} 

가}

관련 문제