创建接收者:
public class LocationUploadReceiver extends BroadcastReceiver {
public static AlarmManager am = null;
public static Intent androidSystemIntent = null;
public static PendingIntent androidSystemPendingIntent = null;
public final static String ACTION_SYSTEM_TIMER = "com.bit.pmcrg.dispatchclient.ACTION_LOCATION_UPLOAD_TIMER";
@Override
public void onReceive(Context context, Intent intent) {
if (LoginManager.getInstance().isOnline() == true)
{
Log.i("zygps001","uploadreceiver收到");
if (GlobalSetting.isLocationServiceEnable() == true) {
Log.i("zygps002","服务开启,可以上报");
MessageSender.getInstance().sendLocationReport();
}
if(GlobalSetting.isMacAddressServiceEnable() == true){
MessageSender.getInstance().sendWifiLocation();
}
AssistantFunctions.setAlarmByVersion(am, SettingParams.getInstance().getGpsPeriod(), androidSystemPendingIntent);
}
}
静态注册:
安卓获取时间
1.System.currentTimeMillis()获取的是系统的时间,可以被修改。是一个标准的“墙”时钟(时间和日期),表示从纪元到现在的毫秒数。该墙时钟能够被用户或电话网络(见setCurrentTimeMillis(long))设置,所以该时间可能会向前或向后不可预知地跳越。该时钟应该仅仅被使用在当现实世界的对应的日期和时间是重要的情况,例如一个日历或闹钟应用程序。
2.SystemClock.elapsedRealtime()获取的是系统开机到现在的时间,不能被修改。是自开机后,经过的时间,包括深度睡眠的时间。适用于任何情况下的时间间隔计算。
3.SystemClock.uptimeMillis():是自开机后,经过的时间,不包括深度睡眠的时间。由于不计算睡眠时间,所以非常适合做一些特殊的时间间隔计算。
https://www.jianshu.com/p/52330c620399



