New Google Play services stuff like low power location

Discussion in 'Android Questions' started by bluedude, May 28, 2013.

  1. bluedude

    bluedude Well-Known Member Licensed User

    I'm compiling with 2.5

    Just one remark, i'm working with B4A 2.5

  2. warwound

    warwound Expert Licensed User

  3. bluedude

    bluedude Well-Known Member Licensed User

    Still need to add permissions


    Now compiling with 2.7 but it does not add the correct permission. I also think it should work without GPS according to the documentation.

    They state that the underlying technology isn't important, that is the reason they created this.

    So for me no luck unfortunately, it gets connected but it does not kick in the listener and location.
  4. warwound

    warwound Expert Licensed User

    Also - i don't think it matters whether you compile with the debug key or whether you compile with a private sign key.
    But if you can try compiling again and instead of using the debug key, use a private key store - see if that changes anything.

    I tried both debug key and private key and it works the same with both so i suspect this is unimportant but posted anyway.

  5. warwound

    warwound Expert Licensed User

    Retrieving the Current Location | Android Developers

    So at least one permission is required.

  6. bluedude

    bluedude Well-Known Member Licensed User


    I never use debug keys, always privately signed. And I also added permission and tried GPS on or off settings. Also tried to change priority but no location gets retrieved unfortunately, even not when on PRIORITY_HIGH_ACCURACY

  7. warwound

    warwound Expert Licensed User

    You've also tried the APK i posted a link to in post #22?

  8. bluedude

    bluedude Well-Known Member Licensed User

    Just tried it, the listener/location never kicks in. Connection works.
  9. warwound

    warwound Expert Licensed User

    I can only think it's a problem with the Google Play Services related stuff.

    Here's the google-play-services.jar library i am using - downloaded using the SDK Manager just a couple of days ago.

    The IsGooglePlayServicesAvailable method does this:

        * Verifies that Google Play services 
    is installed and enabled on this device,
    and that the version installed on this device is no older than the one required by this client.
    public static int IsGooglePlayServicesAvailable(BA pBA){
    I can't see that method returning GooglePlayServicesHelper.SUCCESS if the required service is not available.

    If you visit the Play Store on your device is there an available update for the Google Play Services installed on the device?

  10. bluedude

    bluedude Well-Known Member Licensed User


    I downloaded the latest yesterday and I have the new play store. My play jar is the same as yours and even newer.

    In the logs it also tells me the play services stuff is correct.

  11. bluedude

    bluedude Well-Known Member Licensed User

  12. netchicken

    netchicken Active Member Licensed User

    That would be so easy to make with the new GPS. I think this will be a really important library.
  13. warwound

    warwound Expert Licensed User


    Have you got the example working yet?
    Can you modify the example so that it calls the LocationClient GetLastLocation method after the Connected event is raised and see if that reports a location?

    Sub Process_Globals

    End Sub

    Sub Globals
    Dim LocationClient1 As LocationClient
    Dim LocationListener1 As LocationListener
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    Dim GooglePlayServicesHelper1 As GooglePlayServicesHelper
    Dim ServiceStatus As Int=GooglePlayServicesHelper1.IsGooglePlayServicesAvailable
    Select ServiceStatus
    Case GooglePlayServicesHelper1.SUCCESS
    Log("GooglePlayServicesHelper IsGooglePlayServicesAvailable service available")
    Case Else
    Log("GooglePlayServicesHelper IsGooglePlayServicesAvailable returned: "&ServiceStatus)
    End Select
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    If LocationListener1.IsInitialized Then
    End If
    If LocationClient1.IsInitialized AND (LocationClient1.IsConnected OR LocationClient1.IsConnecting) Then 
    End If
    End Sub

    Sub LocationClient1_Connected
    Dim LocationRequest1 As LocationRequest
    If LocationListener1.IsInitialized=False Then
    End If
       LocationClient1.RequestLocationUpdates(LocationRequest1, LocationListener1)
    Dim LastLocation As Location=LocationClient1.GetLastLocation
    If LastLocation.IsInitialized Then
    Log(LastLocation.Latitude&", "&LastLocation.Longitude)
    Log("LastLocation is not initialized")
    End If
    End Sub

    Sub LocationClient1_ConnectionFailed(ErrorCode As Int)
    Log("LocationClient1_ConnectionFailed ErrorCode="&ErrorCode)
    End Sub

    Sub LocationClient1_Disconnected
    End Sub

    '   ** the GPS library must be enabled to work with Location objects **
    Sub LocationListener1_LocationChanged(Location1 As Location)
    Log(Location1.Latitude&", "&Location1.Longitude)
    End Sub
    Change your device orientation after the Connected event is raised - does GetLastLocation now return an initialized Location?

    Last edited: Jun 2, 2013
  14. warwound

    warwound Expert Licensed User

    Another little progress report here, i've managed to get some of the Geofence functionality working...
    But it seems as though the location service is only using the wifi network location and not hardware GPS.
    I've attached a project and the updated library.

    On my Galaxy Tab2 Jelly Bean it correctly tells me when i am within a Geofence(when i am at home conencted to my home wifi), i took a walk and it failed to tell me when i left the Geofence, but on returning it again told me i was within a Geofence.

    Sounds like it's not using hardware GPS to me.

    Anyway, it's a lovely bright day here in the UK and i'm going out, so i'll work more on the library over the next few days.

    Last edited: Jun 6, 2013
  15. bluedude

    bluedude Well-Known Member Licensed User

    LastLocation works


    It seems lastlocation works, need to drive around little more to see how locationlistener performs.

    Will start testing Geofencing.

  16. bluedude

    bluedude Well-Known Member Licensed User

    Listener locationchange does not work


    Tested a few things and LastLocation works. Listener also gets initialized but does not generate the change event when driving around.

    It seems for High accuracy you need to have GPS on and it does not seem to use an alternative when GPS is off.

    So I guess the Google API isn't that smart yet :)
  17. netchicken

    netchicken Active Member Licensed User

  18. warwound

    warwound Expert Licensed User

    The library is taking shape, after a bit of research i have a new example project that better shows usage of the LocationRequest.

    I've moved all of the location api code into a foreground service and used the AHPreferenceActivity to enable you to choose the parameters used for the LocationRequest.

    It seems as though the problem previously reported by bluedude that the LocationListener LocationChanged event was not being raised was because some default properties of the LocationRequest were being used.
    I started by setting the ExpirationDuration property to a large number of milliseconds and now the event was being raised as expected.
    Without setting this property or incorrectly setting the Geofence NEVER_EXPIRE constant (as i posted previously i think) the LocationRequest was expiring before any LocationChanged events were raised.

    Anyway - the 'find my location' features are now looking good.
    I'm gonna take a drive shortly and see how the example code performs.

    I had a search too for info on the Geofence, and found some disappointing reports where just like my previous Geofence code the device was not using hardware GPS to detect if it entered or exited a Geofence.
    Instead it seemed to only use wifi (maybe 3g too) to establish if the device has entered or exited a Geofence:

    gps - New Android Geofence Api - Sample code does not alert/notify when at location - Stack Overflow

    how to use android geofencing api? - Stack Overflow

    maps - Bug in Android Geofence Sample code? Can anyone please confirm? - Stack Overflow

    These reports are saying that the official google demo code for Geofencing simply does not work (as expected), it fails to use the hardware GPS and instead uses wifi location resulting in a failure to detect entering or exiting a Geofence.

    My next update is to detect entering or exiting Geofences while also listening for a LocationRequest with PRIORITY_HIGH_ACCURACY set to try and force the use of hardware GPS for Geofencing.
    I hope to work on that later and will post again with my results.

    [edit]See next post for updated code and library files[/edit]

    Last edited: Jun 6, 2013
  19. warwound

    warwound Expert Licensed User

    Good news...

    I have a new demo project and it is successfully detecting me entering and exiting a Geofence. In fact i set a 20 metre geofence around my home and strolled up and down the road a few times, my S3 detected me entering and leaving the geofence 3 or 4 times.
    I have all GPS stuff enabled on my S3 - hardware GPS and network location etc.

    I've removed the code and library from my last post and attached all new files to this post.
    And i'll leave everyone that's following this thread to take a look and post their results, comments and any requests.

    The geofencing aspect of the new location apis seems pretty vague and not thoroughly documented, here's another article i found while debugging my previous problem with the geofencing: how to use android geofencing api? | BlogoSfera.
    The main confusion is what location provider(s) does geofencing actually use?
    Does it use only wifi? wifi and 3G?
    Does it ever use hardware GPS?
    So far i have found these questiones asked again and again with not a single real (authorative) answer.

    So give the latest project a try, use the Settings option to enable/disable LocationRequest and/or Geofence and set LocationRequest parameters and enjoy an evening stroll!
    (You'll have to hardcode a Geofence location and radius in the LocationManager service at line ~107).
    Be sure to connect your device to your computer and take a look at the log when you return, recent logs should still display and you should see everything happening.

    If you all report that it is generally working as expected i'll move on to activity detection next and we should see the library complete and ready for use by next week.
    If you make any reports please include details of the device being used and which location providers you have enabled in your device settings.


    Attached Files:

    gudino jose luis likes this.
  20. warwound

    warwound Expert Licensed User


    So i started the demo app as posted in my previous post, enabled a geofence (around my home 10m radius), but disabled LocationRequest.
    The app tells me i've entered the geofence - i was in the geofence when i started the app so this is logical.

    I took a drive to the out of town supermarket, parked my car and took a look at the app.
    It said i was still within the geofence :(.
    Did my shopping, restarted the app and drove home.
    The app did nothing, it didn't tell me when i started my drive home that i wasn't in the geofence and when i got home it didn't detect that i had entered the geofence :(.

    4 members have downloaded the example project so far - have any of you had any luck (good or bad)?

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice