@Override
  public void onReceive(Context context, Intent intent) {
    try {
      Log.i(ApplicationContextClient.class.getName(), "AlarmReceiver:" + intent.getAction());
    } catch (Exception e) {
      System.out.println("AlarmReceiver");
    }
    if (ACTION.equals(intent.getAction())) {
      // 心跳广播
      applicationContextClient.sendHeartBeatMessage();
    } else if (CONNECT_ACTION.equals(intent.getAction())) {
      // 重连广播监听
      try {
        NettyServerManager.reconnect();
      } catch (Exception e) {
        e.printStackTrace();
      }

    } else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
      // 网络状态监听广播接收
      connectivityManager(context);
      NetworkInfo gprs = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
      NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
      if (!gprs.isConnected() && !wifi.isConnected()) {
        // 網絡斷開 了
        // 停止心跳消息发送
        NettyAlarmManager.stopHeart();
        // 停止重连
        NettyAlarmManager.stopReconnection();
      } else {
        // 启动重连
        NettyAlarmManager.startReconnection(context);
      }
    }
  }
Example #2
0
    public void onReceive(Context context, Intent intent) {

      if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
        networkchanged = true;
        //	            	 Log.i(TAG, "-------------------------"+intent.getAction());
      }
    }
  public void onReceive(Context context, Intent intent) {
    Logger.log(TAG, "onReceive#" + intent + ", intent.getExtras()" + intent.getExtras());

    if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
      connectionManagerHandler.onConnectivity();
    } else if (ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED.equals(
        intent.getAction())) {
      connectionManagerHandler.onConnectivity();
    }
  }
Example #4
0
  @Override
  public Integer receive(Context context, Intent intent, Integer tmpWakeLockId) {
    if (K9.DEBUG) Log.i(K9.LOG_TAG, "BootReceiver.onReceive" + intent);

    final String action = intent.getAction();
    if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
      // K9.setServicesEnabled(context, tmpWakeLockId);
      // tmpWakeLockId = null;
    } else if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(action)) {
      MailService.actionCancel(context, tmpWakeLockId);
      tmpWakeLockId = null;
    } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) {
      MailService.actionReset(context, tmpWakeLockId);
      tmpWakeLockId = null;
    } else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
      MailService.connectivityChange(context, tmpWakeLockId);
      tmpWakeLockId = null;
    } else if ("com.android.sync.SYNC_CONN_STATUS_CHANGED".equals(action)) {
      K9.BACKGROUND_OPS bOps = K9.getBackgroundOps();
      if (bOps == K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC) {
        MailService.actionReset(context, tmpWakeLockId);
        tmpWakeLockId = null;
      }
    } else if (FIRE_INTENT.equals(action)) {
      Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
      String alarmedAction = alarmedIntent.getAction();
      if (K9.DEBUG)
        Log.i(K9.LOG_TAG, "BootReceiver Got alarm to fire alarmedIntent " + alarmedAction);
      alarmedIntent.putExtra(WAKE_LOCK_ID, tmpWakeLockId);
      tmpWakeLockId = null;
      context.startService(alarmedIntent);
    } else if (SCHEDULE_INTENT.equals(action)) {
      long atTime = intent.getLongExtra(AT_TIME, -1);
      Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
      if (K9.DEBUG)
        Log.i(
            K9.LOG_TAG,
            "BootReceiver Scheduling intent " + alarmedIntent + " for " + new Date(atTime));

      PendingIntent pi = buildPendingIntent(context, intent);
      K9AlarmManager alarmMgr = K9AlarmManager.getAlarmManager(context);

      alarmMgr.set(AlarmManager.RTC_WAKEUP, atTime, pi);
    } else if (CANCEL_INTENT.equals(action)) {
      Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
      if (K9.DEBUG) Log.i(K9.LOG_TAG, "BootReceiver Canceling alarmedIntent " + alarmedIntent);

      PendingIntent pi = buildPendingIntent(context, intent);

      K9AlarmManager alarmMgr = K9AlarmManager.getAlarmManager(context);
      alarmMgr.cancel(pi);
    }

    return tmpWakeLockId;
  }
 @Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
     // There is connectivity
     final ConnectivityManager connManager =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     final NetworkInfo netInfo = connManager.getActiveNetworkInfo();
     if (netInfo != null) {
       // Verify that it's a WIFI connection
       if (netInfo.getState() == NetworkInfo.State.CONNECTED
           && (netInfo.getType() == ConnectivityManager.TYPE_WIFI
               || netInfo.getType() == ConnectivityManager.TYPE_ETHERNET)) {
         mHandler.obtainMessage(EVENT_NETWORK_CONNECTED).sendToTarget();
       }
     }
   }
 }
Example #6
0
  @Override
  public void onReceive(Context context, Intent intent) {

    if (DEBUG) Log.d(TAG, "Context: " + context.getPackageName());

    if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
      if (DEBUG) Log.d(TAG, "Network connection changed");

      boolean isConnected = isConnected(context);

      if (DEBUG) Log.d(TAG, "Internet connected: " + isConnected);

      if (isConnected) {

        startService(context, Saver.class);
        if (DEBUG) Log.d(TAG, "Saver started");

        if (needToDownloadSchedule(context)) {
          startService(context, FinishedService.class);
        }
      }
    }
  }
 @Override
 public void onReceive(Context context, Intent intent) {
   if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
     AppContext.mNetWorkState = ((AppContext) context.getApplicationContext()).getNetworkType();
   }
 }