How to implement onConnectionFailed() and onDisconnected() for a location service

Peter Warbo

I'm using a Service which implements com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks and com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener

The service is supposed to upload location updates to a server every minute when it's running. I've googled for tutorials but I can't find any good ones for my scenario.

The methods that I don't know how to implement are:

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

    ...
}

There are some tutorials suggesting to start an activity with connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST); but since this is a Service (not an Activity) I can't use this method. I thought of sending the connectionResult in an Intent to an activity but ConnectionResult is not serializable.

and

@Override
public void onDisconnected() {

    ...
}

Should I just call LocationClient#connect() again in here?

Pararth

1. In onConnectionFailed():
For "I thought of sending the connectionResult in an Intent to an activity but ConnectionResult is not serializable." I think it can work without that in the following way:

You can return the int ; ErrorCodes or Constants value of ConnectionResult and depending on that value, you can assign further actions, just pass the control to your activity/application.
From:
http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html

2. In onDisconnected(),
You can notify the user that "you are no longer receiving location updates" or another custom message depending on your app which would prompt the user to take an action.
If your service enters onDisconnected() for some reason we aren't aware of, calling locationClient.connect() again may not help.

In both scenarios, the idea is to pass the control to your app so somewhere in your activity, it can work as a decision point for the control flow.

Also, you have mentioned "...but I can't find any good ones for my scenario." so describing your requirement a bit precisely may help you more. Will edit my answer accordingly.

If its sending location updates to the server, then passing the control back to your activity/app and prompt user also for action would also help. (eg. Check Settings for Location access services enabled)


Current scenario for anybody looking up this question/answer
LocationClient is no longer found under com.google.android.gms.location, refer:
Android play services 6.5: LocationClient is missing

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to implement onConnectionFailed() and onDisconnected() for a location service

From Dev

How to implement mock location?

From Dev

How to implement mock location?

From Dev

How to implement service worker?

From Dev

How to implement a "watchdog" service

From Dev

How to implement service worker?

From Dev

How to implement instagrams location search

From Dev

Manually select location, how to implement?

From Dev

How to implement web service transactions?

From Dev

How to implement web service transactions?

From Dev

How to implement BeaconConsumer with service in android

From Dev

Google play services location stops location updates on resume without calling onDisconnected

From Dev

How to get the exact authorization status of location service?

From Dev

How to add app explanation for location service in settings

From Dev

how to stop a Location listener service? (not stopping now)

From Dev

How to know if Location Service dialog was shown in iOS?

From Dev

How to implement web service consumer SOAP with Mulesoft

From Dev

How to implement communication Activity-Service

From Dev

How to implement push notification service for a crossplatform webapp?

From Dev

How to implement Delete service call using ServiceStack

From Dev

How to implement service after installing application in android

From Dev

How to implement a java code as a service in grails

From Dev

How to Implement URL parameter service correctly

From Dev

How to implement an async method for Design Time service

From Dev

How to implement streaming media player as foreground service?

From Dev

How to implement an Android Service in Xamarin.Forms

From Dev

How to Implement draggable map like uber android, Update with change location

From Dev

How to implement nested location and store it in a database with PHP/MySQL?

From Dev

Android location - no matter how I implement it, I never get the location marker icon in the notification bar

Related Related

  1. 1

    How to implement onConnectionFailed() and onDisconnected() for a location service

  2. 2

    How to implement mock location?

  3. 3

    How to implement mock location?

  4. 4

    How to implement service worker?

  5. 5

    How to implement a "watchdog" service

  6. 6

    How to implement service worker?

  7. 7

    How to implement instagrams location search

  8. 8

    Manually select location, how to implement?

  9. 9

    How to implement web service transactions?

  10. 10

    How to implement web service transactions?

  11. 11

    How to implement BeaconConsumer with service in android

  12. 12

    Google play services location stops location updates on resume without calling onDisconnected

  13. 13

    How to get the exact authorization status of location service?

  14. 14

    How to add app explanation for location service in settings

  15. 15

    how to stop a Location listener service? (not stopping now)

  16. 16

    How to know if Location Service dialog was shown in iOS?

  17. 17

    How to implement web service consumer SOAP with Mulesoft

  18. 18

    How to implement communication Activity-Service

  19. 19

    How to implement push notification service for a crossplatform webapp?

  20. 20

    How to implement Delete service call using ServiceStack

  21. 21

    How to implement service after installing application in android

  22. 22

    How to implement a java code as a service in grails

  23. 23

    How to Implement URL parameter service correctly

  24. 24

    How to implement an async method for Design Time service

  25. 25

    How to implement streaming media player as foreground service?

  26. 26

    How to implement an Android Service in Xamarin.Forms

  27. 27

    How to Implement draggable map like uber android, Update with change location

  28. 28

    How to implement nested location and store it in a database with PHP/MySQL?

  29. 29

    Android location - no matter how I implement it, I never get the location marker icon in the notification bar

HotTag

Archive