public void broadcastLocation(Location location) {
    final LocationProxy bgLocation = LocationProxy.fromAndroidLocation(location);
    bgLocation.setServiceProvider(config.getServiceProvider());

    if (config.isDebugging()) {
      bgLocation.setDebug(true);
      persistLocation(bgLocation);
    }

    Log.d(TAG, "Broadcasting update message: " + bgLocation.toString());
    try {
      String locStr = bgLocation.toJSONObject().toString();
      Intent intent = new Intent(Constant.ACTION_FILTER);
      intent.putExtra(Constant.ACTION, Constant.ACTION_LOCATION_UPDATE);
      intent.putExtra(Constant.DATA, locStr);
      if (config.getUrl() != null) {
        Log.i(TAG, "Sending URL detail");
        intent.putExtra("url", config.getUrl());
        intent.putExtra("method", config.getMethod());
        intent.putExtra("headers", config.getHeaders());
        intent.putExtra("params", config.getParams());
      } else {
        Log.i(TAG, "No URL defined");
      }
      context.sendOrderedBroadcast(
          intent,
          null,
          new BroadcastReceiver() {
            // @SuppressLint("NewApi")
            @Override
            public void onReceive(Context context, Intent intent) {
              Log.d(TAG, "Final Result Receiver");
              Bundle results = getResultExtras(true);
              if (results.getString(Constant.LOCATION_SENT_INDICATOR) == null) {
                Log.w(TAG, "Main activity seems to be killed");
                if (config.getStopOnTerminate() == false) {
                  bgLocation.setDebug(false);
                  persistLocation(bgLocation);
                  Log.d(TAG, "Persisting location. Reason: Main activity was killed.");
                }
              }
            }
          },
          null,
          Activity.RESULT_OK,
          null,
          null);
    } catch (JSONException e) {
      Log.w(TAG, "Failed to broadcast location");
    }
  }
 public void persistLocation(Location location) {
   persistLocation(LocationProxy.fromAndroidLocation(location));
 }