title: How to install PhoneGap Background location plugin for Android?
body: <p>I have found similar questions to this one on Stackoverflow, but all of them answers to one of my questions, but opens a number of ones that I don't really know.</p>
  
  <p>I wanted to use a geo-location plugin for my PhoneGap 3.3.0 application. I wanted to use plugin on address <a href="https://github.com/christocracy/cordova-plugin-background-geolocation" rel="nofollow" title="cordova-plugin-background-geolocation">cordova-plugin-background-geolocation</a></p>
  
  <p>Okay, the install says that it can be used with plugman, so I have installed plugman and installed it with it. (also I have used a phonegap install, instead of cordova, as I am using phonegap <code>plugin plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git</code>) . So, ok, the new Java code  is now placed in <code>/platforms/android/src/com/tenforwardconsulting/cordova/bgloc/BackgroundGpsPlugin.java</code></p>
  
  <p>I have put into my <code>index.html</code> this code (basically the same as said in the plugin):</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  document.addEventListener("deviceready", onDeviceReady, true); 
  
  
      function onDeviceReady() {
              alert('Device ready');
  
  
      //
      // after deviceready
      //
      //
  
  
      var bgGeo = window.plugins.backgroundGeoLocation;
  
      // BackgroundGeoLocation is highly configurable.
      bgGeo.configure(callbackFn, failureFn, {
          url: 'http://only.for.android.com/update_location.json', // &lt;-- only required for Android; ios allows javascript callbacks for your http
          authToken: 'user_secret_auth_token',    // &lt;-- only required for Android; ios allows javascript callbacks for your http
          desiredAccuracy: 10,
          stationaryRadius: 20,
          distanceFilter: 30,
          debug: true // &lt;-- enable this hear sounds for background-geolocation life-cycle.
      });
  
      // Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
      bgGeo.start();
  
  
  }
  
  // Your app must execute AT LEAST ONE call for the current position via standard Cordova geolocation,
      //  in order to prompt the user for Location permission.
      window.navigator.geolocation.getCurrentPosition(function(location) {
          console.log('Location from Phonegap');
           alert("Get current location");
      });
  
  
      /**
      * This would be your own callback for Ajax-requests after POSTing background geolocation to your server.
      */
      var yourAjaxCallback = function(response) {
          ////
          // IMPORTANT:  You must execute the #finish method here to inform the native plugin that you're finished,
          //  and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
          // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
          //
          //
          alert("Callback function");
          //bgGeo.finish();
      };
  
      /**
      * This callback will be executed every time a geolocation is recorded in the background.
      */
      var callbackFn = function(location) {
          console.log('[js] BackgroundGeoLocation callback:  ' + location.latitudue + ',' + location.longitude);
          // Do your HTTP request here to POST location to your server.
          //
          //
          //yourAjaxCallback.call(this);
          alert("Location recorded");
      };
  
      var failureFn = function(error) {
          console.log('BackgroundGeoLocation error');
          alert("BackgroundGeoLocation error");
      }
  
  
  
      // If you wish to turn OFF background-tracking, call the #stop method.
      // bgGeo.stop()
  
      &lt;/script&gt;
  </code></pre>
  
  <p>When I build phonegap and deploy to the Android phone I only get an alert 'Device ready', but any other alert I don't get (You can see I have put on every location an alert just to test it)</p>
  
  <p>Ok, having that said I have <strong>two</strong> questions.</p>
  
  <p><strong>1.</strong> Is this plugin even compatible with PhoneGap 3.3.0 and how I can check that ?</p>
  
  <p><strong>2.</strong> Except installing a plugin with <code>phonegap plugin add https://github.com/christocracy/cordova-plugin-background-geolocation.git</code> what files I have to update to make this plugin workable (plugin.xml, config.xml etc.) and with wath values. I have seen a documentation about adding <code>gap:plugin</code>, but my compiler is complaining. So in general what should I do to make this to work ?</p>
  
  <p>Also, important, I have found an article <a href="http://www.joshmorony.com/background-geolocation-with-phonegap-build/" rel="nofollow">here</a> about using this plugin, but I didn't understand what to put where, so it could be helpful if somebody could help me with it.</p>