Android Question How to understand why geofence wasn't created?

Sandman

Expert
Licensed User
Longtime User
EDIT: I re-read my own post and found it to be overly wordy, confusing and focused on the wrong thing. I'm leaving this here for posterity, and in case it might contain something relevant. New post that hopefully is clearer: https://www.b4x.com/android/forum/threads/getting-info-using-javaobjects-getmethod-etc.128173/

I'm experimenting with geofences on Android (related thread) and have come upon something I can't seem to solve.

I've taken the example by Erel (see the related thread above) and modified Main slightly to add more than one geofence. It seemed to work for a period, but then it stopped working by simply not allowing to add more geofences at app relaunch.

In GeofenceService there is this code, as Erel wrote it:
B4X:
Public Sub AddGeofence(Callback As Object, geo As Geofence)
    Dim gb As JavaObject = CreateGeofenceBuilder(geo)
    Dim req As JavaObject = CreateGeofenceRequest(gb)
    Dim task As JavaObject = client.RunMethod("addGeofences", Array(req, PendingIntent))
    Do While task.RunMethod("isComplete", Null) = False
        Sleep(50)
    Loop
    CallSubDelayed2(Callback, "Geofence_Added", task.RunMethod("isSuccessful", Null))
End Sub

Look at the last line. The isSuccessful returns TRUE initially, but then switches to FALSE after a couple (one?) of app relaunches.

I've been looking at the documentation that seem relevant to me:
I'm trying to understand why the app fails in adding geofences, so it seems reasonable to work my way to GeofenceStatusCodes. (That assumption might be wrong.) This is as far as I come:
B4X:
Public Sub AddGeofence(Callback As Object, geo As Geofence)
    Dim gb As JavaObject = CreateGeofenceBuilder(geo)
    Dim req As JavaObject = CreateGeofenceRequest(gb)
    Dim task As JavaObject = client.RunMethod("addGeofences", Array(req, PendingIntent))
    Do While task.RunMethod("isComplete", Null) = False
        Sleep(50)
    Loop
    CallSubDelayed2(Callback, "Geofence_Added", task.RunMethod("isSuccessful", Null))
  
    ' Below added by me
    Dim exc As JavaObject = task.RunMethod("getException", Null)
    Log(exc.RunMethod("getStatusCode", Null))
End Sub

When I run this, the Log at the bottom returns 13, which doesn't match the listed values for GeofenceStatusCodes even a little bit. So I think I'm completely lost here.

Any suggestions?
 
Last edited:
Top