java – Localização em segundo plano android studio

———- Esse o o meu serviço

Public class LocationMonitoringService extends the service implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
LocationListener {

static private end String TAG = LocationMonitoringService.class.getSimpleName ();
GoogleApiClient mLocationClient;
LocationRequest mLocationRequest = new LocationRequest ();


String public static end ACTION_LOCATION_BROADCAST = LocationMonitoringService.class.getName () + "LocationBroadcast";
Public String final String EXTRA_LATITUDE = "extra_latitude";
Public String final String EXTRA_LONGITUDE = "extra_longitude";

@Cancel
public int onStartCommand (intention intent, int indicators, int startId) {
mLocationClient = new GoogleApiClient.Builder (this)
.addConnectionCallbacks (this)
.addOnConnectionFailedListener (this)
.addApi (LocationServices.API)
.build();

mLocationRequest.setInterval (Constants.LOCATION_INTERVAL);
mLocationRequest.setFastestInterval (Constants.FASTEST_LOCATION_INTERVAL);


int priority = LocationRequest.PRIORITY_HIGH_ACCURACY; //default
// PRIORITY_BALANCED_POWER_ACCURACY, PRIORITY_LOW_POWER, PRIORITY_NO_POWER are the other priority modes


mLocationRequest.setPriority (priority);
mLocationClient.connect ();

// Set it to the notification panel so that it is less likely to be canceled by the operating system.
return START_STICKY;
}

@Nullable
@Cancel
public IBinder onBind (intentional intention) {
zero return
}

/ *
* LOCALIZATION OF CALLS
* /
@Cancel
public void onConnected (Bundle dataBundle) {
if (ActivityCompat.checkSelfPermission (this, Manifest.permission.ACCESS_FINE_LOCATION)! = PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission (.Personal.permission.ACCESS_COARSE_LOCATION)! = PackageManager.Perque
// ALL: Consider calling
// ActivityCompat # requestPermissions
// here to request the missing permissions, and then cancel
// public void onRequestPermissionsResult (int requestCode, String[] permissions,
// In t[] grantResults)
// to handle the case where the user grants permission. See the documentation
// for ActivityCompat # requestPermissions for more details.

Log.d (TAG, "== Error On onConnected () Permission not granted");
// Permission not granted by the user so cancel the additional execution.

he came back;
}
LocationServices.FusedLocationApi.requestLocationUpdates (mLocationClient, mLocationRequest, this);

Log.d (TAG, "Connected to the Google API");
}

/ *
* Called by Location Services if the connection to the
* The location client falls due to an error.
* /
@Cancel
public void onConnectionSuspended (int i) {
Log.d (TAG, "Connection suspended");
}

// to get the location change
@Cancel
public void onLocationChanged (location location) {
Log.d (TAG, "Location changed");


if (location! = null) {
Log.d (TAG, "== location! = Null");

// Send result to activities.
sendMessageToUI (String.valueOf (location.getLatitude ()), String.valueOf (location.getLongitude ()));

}
}

private void sendMessageToUI (String lat, String lng) {

Log.d (TAG, "Sending information ... latitude:" + lat + "| length:" + lng);

Intent intention = new Intent (ACTION_LOCATION_BROADCAST);
intent.putExtra (EXTRA_LATITUDE, lat);
intent.putExtra (EXTRA_LONGITUDE, lng);
LocalBroadcastManager.getInstance (this) .sendBroadcast (intention);
}

@Cancel
public void onConnectionFailed (ConnectionResult connectionResult) {
Log.d (TAG, "Error connecting to the Google API");

}
@Cancel
public void onDestroy () {
// Stop the service sharing the location on the application server .........

stopService (new Intent (this, LocationMonitoringService.class));
Log.d (TAG, "OnDestroy");
// Ends ............................................... .
super.onDestroy ();
}

}

———- esse o o meu manifest





















    
        
            
        
    
    

    
        
            
            
            
        
    
    
        
            
        
    
    
        
            
        
    

A localização is vindo legal em primeiro plano porem in the second plane ela for y eu gostaria that ela viece to fazer a kind of localizer pessoal

OBS (when it was in separate applications ela trazia, porem quinta juntei os app ela parou to shoot in the background …