Error adding geofences in Android (status code 1000)
Asked Answered
I

12

38

I am getting an error in the onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) callback with statusCode = 1000.

I have my GPS enabled and my WiFi. I also have Google Play Services and I am able to track my location and request updates. Why am I not able to add geofences? I am not able to add geofences even from the documentation sample app. I get the following Toast message:

"Add Geofences: Failure, error code 1000 GeofenceRequestIds=[1,2,1,2]"

From the documentation (statusCode 1000):

public static final int GEOFENCE_NOT_AVAILABLE

Geofence service is not available now. Typically this is because the user turned off location access in settings > location access.

Constant Value: 1000 (0x000003e8)

Indirection answered 29/9, 2013 at 19:44 Comment(0)
T
43

You get GEOFENCE_NOT_AVAILABLE (code '1000') when user disagrees to "Use Google' location services" in Settings->Location->Mode: enter image description here

To fix it:

  • go to Settings->Location->Mode
    enter image description here
  • set "Device only (Use GPS to determine your location)"
  • set any other option to get the popup (e.g. "High accuracy (Use GPS, Wi-Fi and mobile networks to determine location")
  • dialog ""Use Google' location services" is shown
  • choose "Agree"
Thomsen answered 27/11, 2014 at 11:15 Comment(5)
thats not very helpful comment, what does not work, hat device, what os?Dunite
I'm getting Status{statusCode=unknown status code: 1000, resolution=null} after GeofencingClient.addGeofences() and the emulator has Mode set to Device only. Emulator image is using Android 7.1.1 with Google API'sDesist
UPDATE: I just now set the Settings -> Location -> Mode to High Accuracy and I was able to set the geofence successfully ! (I hate working with GPS on Android!)Desist
I've found that on a real device, using Device only works just fine to set a geofence. (as does Battery Saving)Desist
@SomeoneSomewhere I get the same status code 1000 when using Device only mode on Galaxy S6Revolutionize
R
15

Posting this answer since the settings in Android have changed a lot. I had this error twice when I was running a Nexus 5X emulator running API 28. I managed to solve it both times by doing the following:

  1. Turn off your application you are developing (don't let it be in the background)
  2. Go to Settings -> Security & Location -> Location -> Advanced -> Google Location Accuracy. Turn 'Improve Location Accuracy' off.

enter image description here

  1. Turn on 'Improve Location Accuracy'

Turn on your application again and adding geofences worked for me after I took these steps.

EDIT: I ran into this issue again a few months later, sometimes the emulator is stubborn and does not actually turn on location accuracy correctly to allow Google's Geofence API to recognise it is turned on. I had turn 'Improve Location Accuracy' on and off at least 10 times before location accuracy worked.

Rockwood answered 3/3, 2019 at 0:22 Comment(4)
For an APK 28 emulator toggling this on fixed the error.Carvalho
@Carvalho asking this for others in the future, did you have to toggle it multiple times before it worked?Rockwood
As of today (20th March 2020), question is still receiving upvotes; assuming this answer is still relative.Rockwood
As of today, still receiving upvotes; assuming this answer is still relative.Rockwood
H
6

Is a little later, but just now I had this issue. My guess is:

you are using any kind of fake GPS on your tests (Lockito, emulator, etc)?

I took some hours until I found out that the fake locations seems to disable the Geofence support! You cannot register or trigger a Geofence if you are not really in the location.

If you turn off the fake GPS,the Geofence support become enabled again.

Hornbill answered 15/11, 2016 at 5:39 Comment(0)
N
5

I was getting the statusCode 1000 when i was trying to run this app on the emulator. The thing which fixed this was to go in Settings-> locations and access-> Check the enable wifi and gps option on the emulator and it will fix it

Neuropathy answered 23/10, 2013 at 22:43 Comment(0)
A
2

You actually gave the answer in your question: Geofence service is not available now. Typically this is because the user turned off location access in settings > location access.

I had this same issue, and just going to settings --> location and making sure I select the mode for high accuracy fixed this issue.

PS Device only mode is not good enough, it needs to be High accuracy mode.

Hope this helps.

Armour answered 25/2, 2014 at 16:57 Comment(0)
B
1

First of all your phone must be compatible: A compatible Android device that runs Android 2.2 or higher and includes Google Play Store.

Just to be sure, you need to have Google Play service installed correctly.

Sometimes, just restarting your phone can fix this problem.

Hope this help.

Benia answered 2/10, 2013 at 15:56 Comment(0)
D
1

This error occurs also when location service is not enabled. You need to set it enabled.

Dole answered 15/7, 2020 at 10:6 Comment(0)
S
0

I did silly mistake:

Error occurred because Device does not have Permission for GPS (Location service).

More details on Geofencing API here.

Screen shots for reference:

enter image description here enter image description here

Hope this will make you clear.

Setter answered 24/12, 2015 at 11:40 Comment(0)
A
0

For my targetSdkVersion 28 and minSdkVersion 24, this is what worked for me on emulator running Pixel XL API 27:

I selected High accuracy in the Settings -> Location -> Mode. Originally it was set to Device only.

This popped up a message to with Agree and Disagree options. I selected Agree.

After that the error went away.

I tried the other option Battery Saving. This also worked fine.

But when reverted back to Device only, it started giving this error again.

So in case of emulator Location mode should bet set to High accuracy or Battery saving.

On my actual device, which is a Nexus 6P device, it was already set to High accuracy and I haven't checked it for Device only.

enter image description here

Archangel answered 26/10, 2019 at 0:2 Comment(0)
K
0

Follow this official link to make broadcast for geofence.

https://developer.android.com/training/location/geofencing#java

"make sure that you call your Geofence.Builder and geofencingClient.addGeofences methods in onStart of your mainActivity after you have called googleApiClient.connect()."

then finally if you set location mode in settings i.e GPS or wifi only. You will get this error.(in case u are using emulator) Choose high accuracy mode and you will be able to add geofences. Hope this helps. Best Of Luck.

Karlsruhe answered 17/11, 2019 at 15:34 Comment(0)
A
0

In Android 9.0: I read MinistryOfChaps answer and I tried do this for one hour but it has not worked to me. So I turned off my app, turned off 'Improve Location Accuracy', turned off Scanning > wi-fi scanning and bluetooth scannig, and I turned off my User location too. After this, I turn on all these options and my geofence finally is working

Alsworth answered 29/6, 2020 at 17:13 Comment(0)
H
0

for android oreo to android S make sure to access setting high priority

fun ceksetting(){
val builder = LocationSettingsRequest.Builder()
        .addLocationRequest(locationRequest)
val locationRequest = LocationRequest()
    locationRequest!!.interval = 50000
    locationRequest!!.fastestInterval = 50000
    locationRequest!!.smallestDisplacement = 170f // 170 m = 0.1 mile
    locationRequest!!.priority = LocationRequest.PRIORITY_HIGH_ACCURACY //set according to your app function
    val client: SettingsClient = LocationServices.getSettingsClient(requireActivity())
    val task: Task<LocationSettingsResponse> = client.checkLocationSettings(builder.build())
    task.addOnSuccessListener { locationSettingsResponse ->
       //here call your geofence
    }

    task.addOnFailureListener { exception ->
        if (exception is ResolvableApiException){
            // Location settings are not satisfied, but this can be fixed
            // by showing the user a dialog.
            try {
                // Show the dialog by calling startResolutionForResult(),
                // and check the result in onActivityResult().
                exception.startResolutionForResult(requireActivity(),
                    REQUEST_CHECK_SETTINGS)
            } catch (sendEx: IntentSender.SendIntentException) {
                // Ignore the error.
            }
        }
    }
}
Hitchcock answered 16/4, 2021 at 21:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.