Exemplo n.º 1
0
  @Override
  public int onStartCommand(final Intent intent, final int flags, final int startId) {

    String captureServiceStatus;
    final String uploadType = intent.getStringExtra(UPLOAD_TYPE);
    uploadTime = System.currentTimeMillis();

    if (uploadType.equals(CANCEL_ALARM)) {
      cancelUploadAlarm(this);
    } else if (uploadType.equals(MANUAL_UPLOAD)) {
      uploadeSession();
    } else if (uploadType.equals(AUTO_UPLOAD)) {

      final Intent intentStatus = new Intent(LocationService.ACTION_QUERY_STATUS_UPLOAD_SERVICE);
      LocalBroadcastManager.getInstance(this).sendBroadcastSync(intentStatus);

      captureServiceStatus =
          intentStatus.getStringExtra(LocationService.PARAM_LOCATION_SERVICE_STATUS);

      if (LocationService.STATUS_CAPTURING_LOCATIONS.equals(captureServiceStatus)
          | db.getQueuedLocationsCount(uploadTime) > 0) {
        setAutoUpdate();
      }

      uploadeSession();
    }

    Log.d(UPLOAD_SERVICE_TAG, "exiting service");
    return Service.START_NOT_STICKY;
  }
Exemplo n.º 2
0
  private boolean uploadPossible(final long uploadTime) {
    final boolean userValidation = myPreference.userDetailsNotNull();
    final boolean serverLocationValidation = myPreference.serverLocationSet();
    final boolean dbValidation = db.getQueuedLocationsCount(uploadTime) > 0;
    final boolean networkValidation = isNetworkAvailable(this);
    boolean possible = true;
    final StringBuffer message = new StringBuffer();
    message.append("Upload not possible due to : ");

    if (!userValidation) {
      possible = false;
      message.append("\nUserID or PassKey not provided");
    }

    if (!serverLocationValidation) {
      possible = false;
      message.append("\nServer Location not set");
    }

    if (!dbValidation) {
      possible = false;
      message.append("\nNo locations to upload");
    }

    if (!networkValidation) {
      possible = false;
      message.append("\nNetwoek not available");
    }

    if (!possible) {
      getApplication().startActivity(UserError.makeIntent(getBaseContext(), message.toString()));
      cancelUploadAlarm(this);
    }

    return possible;
  }