Geofences not available and how to handle it

I work with geofences on Android, everything works fine on most phones, but on some of them it just doesn’t work (showing "geo-photos unavailable" in my error logs).

Some users do not have location tracking for Google Play services. I think that’s why geoprocessing doesn’t work on my phones. (Correctly?)

Now I want to find a way to detect this. (tell the user and ultimately show them how to fix it) I know there is a way to find out if google game services are available or not (and I'm already doing this), but this doesn’t mean that location services are enabled or not.

I know that I can check it when adding or removing geopotential, there is an error code for it (geofonus is not available Location status codes ), but this is not enough. Some users turned off location services after adding geo objects. Then I do not know this, and my application will not work. (complaining users, etc.). At least I have to tell the user when they open the application to check what is wrong.

Does anyone have an idea on how to do this? The best I can do now is add and remove a dummy geofound when the application loads, but should there be a better way?

EDIT: I tested it with a device that had a problem, uninstalling the application and reinstalling seems to fix the problem. I am not doing anything special on first boot, so this is really weird. There seems to be a problem connecting to google gaming services, and reinstalling the application does something special with these services. Is it possible? It does not give errors when connecting to them, but this happened when I tried to set geo objects (see above).

+4
source share
1 answer

( ), GPS - . , onAddGeofencesResult() (1000). .

, , android.location.PROVIDERS_CHANGED. AndroidManifest

<receiver android:name=".service.GeofenceProvidersChangedBroadcastReceiver">
    <intent-filter>
        <action android:name="android.location.PROVIDERS_CHANGED"/>
    </intent-filter>
</receiver>

onReceive() :

public class ProvidersChangedBroadcastReceiver extends WakefulBroadcastReceiver {

    :
    :

    @Override
    public void onReceive(Context context, Intent intent) {

        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            // GPS_PROVIDER IS enabled...
        } else {
            // GPS_PROVIDER is NOT enabled...
        }

        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            // NETWORK_PROVIDER IS enabled...
        } else {
            // NETWORK_PROVIDER is NOT enabled...
        }

        :
        :
        :

        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) &&
        locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        // We are good for geofencing as both GPS and Network providers are enabled....
    }

    :
    :
    :

}
+5

Source: https://habr.com/ru/post/1524047/


All Articles