Compare commits
No commits in common. "8bfdaf761c63af023e2cf5dae0acbe4107cbbe70" and "e1241a01c30dc64afc8c306369fca54835479606" have entirely different histories.
8bfdaf761c
...
e1241a01c3
|
|
@ -9,7 +9,6 @@ import com.google.gson.JsonSyntaxException;
|
|||
import com.nbee.echolink.R;
|
||||
import com.nbee.echolink.model.DeviceInfo;
|
||||
import com.nbee.echolink.response.ApiResponse;
|
||||
import com.nbee.echolink.service.MonitorService;
|
||||
import com.nbee.echolink.utils.DeviceInfoUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -30,8 +29,6 @@ public class HeartbeatAlarmReceiver extends BroadcastReceiver {
|
|||
context = context1;
|
||||
// 例如,你可以启动一个服务或者直接在这里执行网络请求
|
||||
sendHeartbeatSignal();
|
||||
// 重新设置下一个闹钟
|
||||
MonitorService.scheduleHeartbeat(context);
|
||||
}
|
||||
|
||||
private void sendHeartbeatSignal() {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class MonitorService extends Service {
|
|||
Timber.d("监控服务 onCreate");
|
||||
startForegroundService();
|
||||
networkUtil = new NetworkUtil(this);
|
||||
scheduleHeartbeat(this); // 启动心跳定时任务
|
||||
scheduleHeartbeat(); // 启动心跳定时任务
|
||||
}
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
|
@ -140,10 +140,10 @@ public class MonitorService extends Service {
|
|||
return null; // 不提供绑定服务的接口
|
||||
}
|
||||
|
||||
public static void scheduleHeartbeat(Context context) {
|
||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
Intent intent = new Intent(context, HeartbeatAlarmReceiver.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
|
||||
private void scheduleHeartbeat() {
|
||||
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
Intent intent = new Intent(this, HeartbeatAlarmReceiver.class); // HeartbeatAlarmReceiver是一个BroadcastReceiver
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
|
||||
|
||||
long intervalMillis = HEARTBEAT_INTERVAL_MINUTES * 60 * 1000; // 10分钟的毫秒数
|
||||
|
||||
|
|
@ -155,5 +155,4 @@ public class MonitorService extends Service {
|
|||
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalMillis, pendingIntent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue