OnResult () en Awareness.SnapshotApi.getLocation NO se llama desde un servicio
Estoy tratando de obtener la ubicación de un Service
fondo. El problema es que la función onResult()
dentro de la Awareness.SnapshotApi.getLocation(mGoogleApiClient).setResultCallback(new ResultCallback<LocationResult>()
no se recibe. ¿Qué podría estar mal aquí?
Las funciones onConnected()
y onConnectionSuspended()
también no reciben llamadas, pero cuando mGoogleApiClient.isConnected() = true
se devuelve.
- ¿Debo usar PendingIntent.getService () o getBroadcast con AlarmManager?
- PARTIAL_WAKE_LOCK vs SCREEN_DIM_WAKE_LOCK en el subproceso de descarga
- Registrador de clave de Android
- Null intent redelivered to Service onStartCommand ()
- Temporizador Se ralentiza en Servicio cuando se bloquea la pantalla del dispositivo
Así que estoy tratando de entender por qué onConnected()
no se llama tampoco.
public class BlockingService extends Service implements GoogleApiClient.ConnectionCallbacks { private GoogleApiClient mGoogleApiClient; @Override public int onStartCommand(Intent intent, int flags, int startId) { initAwarenessAPI(); amIClosetoLocation(<LatLng I get from my database>); return START_NOT_STICKY; } @Override public void onDestroy() { if (mGoogleApiClient.isConnected()) { mGoogleApiClient.disconnect(); } super.onDestroy(); } private void initAwarenessAPI() { Context context = getApplicationContext(); mGoogleApiClient = new GoogleApiClient.Builder(context) .addApi(Awareness.API) .build(); mGoogleApiClient.connect(); } private Boolean amIClosetoLocation(final LatLng savedLoc) { final String TAG = "Awareness"; mLog.printToLog(className + Constants.funcStart + MethodName.methodName() + ": Entered Function"); amIClosetoLocation = false; if (ContextCompat.checkSelfPermission( getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { mLog.printToLog(className + MethodName.methodName() + ": ***DONT HAVE LOCATION PERMISSION***"); } else { mLog.printToLog(className + MethodName.methodName() + ": Permission Exists -- so now going to get location"); Awareness.SnapshotApi.getLocation(mGoogleApiClient) .setResultCallback(new ResultCallback<LocationResult>() { @Override public void onResult(@NonNull LocationResult locationResult) { //THIS FUNCTION IS NOT GETTING CALLED if (!locationResult.getStatus().isSuccess()) { Log.e(TAG, "Could not get location."); mLog.printToLog(className + MethodName.methodName() + ": Could NOT get location"); return false; } else { mLog.printToLog(className + MethodName.methodName() + ": Success: Able to send location"); } Location currLocation = locationResult.getLocation(); mLog.printToLog(className + MethodName.methodName() + ": Success, Received location = " + currLocation.toString()); mLog.printToLog(className + Constants.funcStart + MethodName.methodName() + ": Got Location = Lat: " + currLocation.getLatitude() + ", Lon: " + currLocation.getLongitude()); } }); } mLog.printToLog(className + Constants.funcEnd + MethodName.methodName() + ": Exiting Function, returning amIClosetoLocation = " + amIClosetoLocation); return amIClosetoLocation; } @Override public void onConnected(@Nullable Bundle bundle) { mLog.printToLog(className + Constants.funcStart + MethodName.methodName() + ": Entered Function"); @Override public void onConnectionSuspended(int i) { } }
- Android: stopService () no llama a onDestroy ()!
- Servicio de Android que se reinicia cuando se cancela la aplicación
- AlarmManager no se repite
- Android: ¿puedo usar Google Analytics dentro de un servicio?
- Mantener un servicio en ejecución aunque la aplicación esté cerrada.
- Desactivar ocultar una presentación (pantalla secundaria)
- ¿Cómo establecer una comunicación bidireccional entre Actividad y Servicio en diferentes procesos?
- Subir archivo grande en segundo plano (el servicio se reinicia cuando la aplicación se cierra)
new GoogleApiClient.Builder(context)
segundo parámetro de new GoogleApiClient.Builder(context)
es el oyente de devolución de llamada y lo perdiste.
Quiero decir: new GoogleApiClient.Builder(context, this)
- Cambiar el tamaño del texto en <selector> cuando state_pressed = true
- Emulador de Android siempre con 533MB de almacenamiento interno