Is geofencing completely unusable in Android?
Asked Answered
E

1

17

Because of this bug my team is deciding to not use geofencing at all. Is geofencing in Android something that is usable or not?

From the bug report:

On all in-house test devices everything runs fine with debug and release builds. However, for some users out there we get crash reports that indicate a problem with the API:

Fatal Exception: java.lang.SecurityException: Invalid API Key for package = de.stocard.stocard .Status code received = -1
       at android.os.Parcel.readException(Parcel.java:1620)
       at android.os.Parcel.readException(Parcel.java:1573)
       at com.google.android.gms.common.internal.zzu$zza$zza.zza(Unknown Source)
       at com.google.android.gms.common.internal.zzd.zzqz(Unknown Source)
       at com.google.android.gms.internal.zzpw$zzc.zzapl(Unknown Source)
       at com.google.android.gms.internal.zzpw$zzf.run(Unknown Source)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
       at com.google.android.gms.internal.zzrn.run(Unknown Source)
       at java.lang.Thread.run(Thread.java:818)

This happens on Android versions ranging from 4.4.2 to 7.0 with no noticeable pattern. The same applies to the device model and manufacturer: many and multiple manufacturers and models.

That sounds like a pretty severe Heisenbug.

Update:

There seems to be 2 different ways to do geofencing in Android:

  1. Using the Awareness[.fence] API
  2. Using the location Geofence API

We would need to use the Awareness API to get the features and battery-friendliness we desire.

NOTE:

I see 1 close vote due to "primarily opinion-based". So, let me be clear, I don't want unsupported opinion answers. I want facts, references, or specific expertise. I have done research and referenced a random crash bug with no reliable work around. I want others to note that they have successfully implemented geofencing and have either:

  1. Evidence that their apps have never encountered this bug (good crash reporting that has never caught Invalid API Key for package)
  2. Have seen this bug and have successfully implemented a fix
  3. Never seen this bug
Ebro answered 6/2, 2017 at 21:52 Comment(12)
Have you tried using the Google's geofencing api directly vs using the awareness api?Scuba
I have not. I suggested using Android geofencing for a feature in our application. Another developer came back with, "I tried that at another company and it's broken; Here's the bug ticket." So now I'm trying to get feedback from any developers who may have evidence that geofencing in Android can be done today.Ebro
I haven't used the Awareness API so I can't speak to how well or badly it works. However, I haven't seen this bug in the two years I have spent using the Geofencing API. I would say the Geofencing API has its own set of problems in regards to accuracy, timing, false events, and availability, but this bug seems to be related to the Awareness API only.Scuba
My understanding is that the Awareness API is supposed to replace others including the Geofence API.Ebro
I was under the impression that it was just another API to simplify use Google's other APIs. I haven't seen anything anywhere saying that Awareness was supposed to replace Geofence.Scuba
"My understanding is that the Awareness API is supposed to replace others". Oh? And where do you get that from?Stiegler
@SimonH From Google I/O presentations.Ebro
Well hopefully they will fix it in the Awareness API then :) Meantime I am happy using Geofencing on com.google.android.gms.location with no problems (including battery friendliness). I'd be shocked if they remove it from there.Stiegler
I'm using the location Geofence API with no problem like you describe above. You can check out parts of the code here github.com/Turistforeningen/SjekkUT/blob/master/android/app/src/… - it seems accurate and I haven't noticed it being a powerhog when running in the background. If you have to use the Awareness API then I can't help you, but the other one albeit clunky, seems to work fine.Tolly
i have use googles geofencing is betterIndisputable
I know you use Google API, but personnaly, I used the LocationManager.addProximityAlert() way, no Google API being involved, there is no such problem...Melancholic
I would ask people specifically to "STAR" the bug report. That way it will get fixed. I need to know that this is something caused by a null pointer like on a restart or orintation change for my own self before I see it. How are you doing onpause onresume may lead to where a null check is needed. I know you mentioned task in a service what the service is that and no code is provided. How are you restarting the service. It happens I might end the service if I'm troubleshooting a bat problem on a device.Gahan
F
1

The bug you linked already contained all the information, didn't it?

There is a bug in our checks that is sometimes throwing this SecurityException when there is a network error to authenticate. The fix will rollout in the next version of Google Play services.

For now, the best workaround would be set up an UncaughtExceptionHandler on the thread that you call GoogleApiClient.connect(). For most folks, this would be on the main thread, which you can get via Looper.myLooper().getThread().

Update

Well, to answer your question "Is geofencing completely unusable in Android?", I'd say no, it is not "completely" unusable but obviously contains a few issues.

Should you not use geofencing at all because of these bugs? I guess that heavily depends on the use case and is indeed an opinion based question. As always with mobile devices, you can never be 100% sure if something works. Your mobile might have no signal and even if there were no bugs in the code it might still not get notified about a certain location for various reasons. On mobile it's all about how you deal with errors.

I'd implement whatever you want to implement, try to do what was suggested in the bug ticket (the UncaughtExceptionHandler) to catch the error and implement analytics/crash reports in the app so that you at least will get information about how often this really happens out there in the field.

Make it clear to your users that there is no 100% guarantee that the geofence feature of your app works at all times due to the underlying system and I think they will still be happy to have the feature. Probably have some FAQ somewhere in your app or on your homepage which adresses the known issues. Hope this helps you make a decission

Fancy answered 4/4, 2017 at 3:41 Comment(1)
There are several other comments in the thread that indicate that suggestion is NOT resolving the issue. Also, 18 days after this question was asked, Google released an update that should fix the issue. However, there are comments on that thread as recently as yesterday that say they are still seeing it.Ebro

© 2022 - 2024 — McMap. All rights reserved.