Geofire updating background location

Asked

Viewed 152 times

0

I’m making an application , the location system is similar to the Uber , who needs to send the location to firebase from 3 in 3 seconds , to get the current location live , but when the app is in the background , he stops updating , can help me?

the code that sends the data to firebase is this

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
            ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    Common.mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    if (Common.mLastLocation != null )
    {
        if (location_switch.isChecked())
        {
            final double latitude = Common.mLastLocation.getLatitude();
            final double longitude = Common.mLastLocation.getLongitude();

            //// PASSAR DADOS PARA O FIREBASE
            geoFire.setLocation(FirebaseAuth.getInstance().getCurrentUser().getUid(), new GeoLocation(latitude, longitude), new GeoFire.CompletionListener() {
                @Override
                public void onComplete(String key, DatabaseError error) {
                    // ADICIONA MARCADOR NO MAPA
                    if (mCurrent != null)
                        mCurrent.remove();
                    mCurrent = mMap.addMarker(new MarkerOptions()

                            .position(new LatLng(latitude, longitude))

                            .title("Voce"));



                    /// Movimentar camera para sua posicao
                    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15.0f));
  • When you close Activity, you kill mGoogleApiClient?

  • @Thiagoluizdomacoski when minimizes already kills alone does not kill?

  • http://adavis.info/2014/09/android-location-updates-with-the-fusedlocationapi.html look at this example! it pauses, and onResume returns

  • The ideal would be to separate into two parts: A service that picks up the location and sends it to the server. And the screen, just consume the data of this service.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.