Geofence for xamarin crossplatform

时光怂恿深爱的人放手 提交于 2019-12-11 09:08:33

问题


I currently implemented a geofencing plugin for xamarin from DevEddy (I used this because it had a sample project and it was updated more recently). And it kind of works correctly.

The problem: When I set my android Location mode/proviedr settings to "Use GPS only (Device Only)" Instead of gps,wifi,mobile networks and run my app it breaks, and send the following error:

Android.Gms.Common.Apis.ApiException: 1000:

The whole output:

Unhandled Exception:

Android.Gms.Common.Apis.ApiException: 1000: 

11-12 11:01:08.337 D/Mono    ( 5466): DllImport attempting to load: '/system/lib64/liblog.so'.
11-12 11:01:08.338 D/Mono    ( 5466): DllImport loaded library '/system/lib64/liblog.so'.
11-12 11:01:08.338 D/Mono    ( 5466): DllImport searching in: '/system/lib64/liblog.so' ('/system/lib64/liblog.so').
11-12 11:01:08.338 D/Mono    ( 5466): Searching for '__android_log_print'.
11-12 11:01:08.338 D/Mono    ( 5466): Probing '__android_log_print'.
11-12 11:01:08.338 D/Mono    ( 5466): Found as '__android_log_print'.
11-12 11:01:08.343 I/MonoDroid( 5466): UNHANDLED EXCEPTION:An unhandled exception occured.


11-12 11:01:08.357 D/Mono    ( 5466): DllImport searching in: '__Internal' ('(null)').
11-12 11:01:08.357 D/Mono    ( 5466): Searching for 'java_interop_jnienv_is_assignable_from'.
11-12 11:01:08.357 D/Mono    ( 5466): Probing 'java_interop_jnienv_is_assignable_from'.
11-12 11:01:08.358 D/Mono    ( 5466): Found as 'java_interop_jnienv_is_assignable_from'.
11-12 11:01:08.366 I/MonoDroid( 5466): Android.Gms.Common.Apis.ApiException: 1000: 
11-12 11:01:08.366 I/MonoDroid( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at Plugin.Geofencing.GeofencingImplementation+<StartMonitoring>d__10.MoveNext () [0x000f0] in <aa9ff56f4a7a4b72b03925c3bf41ed1d>:0 
11-12 11:01:08.366 I/MonoDroid( 5466): --- End of stack trace from previous location where exception was thrown ---
11-12 11:01:08.366 I/MonoDroid( 5466):   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <a10f61e70eeb434e952fef884856c199>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <a10f61e70eeb434e952fef884856c199>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <a10f61e70eeb434e952fef884856c199>:0 
11-12 11:01:08.366 I/MonoDroid( 5466):   at (wrapper dynamic-method) System.Object.38(intptr,intptr)
11-12 11:01:08.366 I/MonoDroid( 5466):   --- End of managed Android.Gms.Common.Apis.ApiException stack trace ---
11-12 11:01:08.366 I/MonoDroid( 5466): com.google.android.gms.common.api.ApiException: 1000: 
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.common.internal.zzb.zzx(Unknown Source:14)
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.common.internal.zzbj.zzy(Unknown Source:0)
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.common.internal.zzbk.zzq(Unknown Source:32)
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.common.api.internal.zzs.zzc(Unknown Source:46)
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.common.api.internal.zzs.setResult(Unknown Source:40)
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.location.LocationServices$zza.setResult(Unknown Source:2)
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.internal.zzbzv.zza(Unknown Source:22)
11-12 11:01:08.366 I/MonoDroid( 5466):  at com.google.android.gms.internal.zzbzj.onTransact(Unknown Source:22)
11-12 11:01:08.366 I/MonoDroid( 5466):  at android.os.Binder.execTransact(Binder.java:675)
11-12 11:01:08.366 I/MonoDroid( 5466): 
11-12 11:01:08.374 D/Mono    ( 5466): DllImport searching in: '__Internal' ('(null)').
11-12 11:01:08.374 D/Mono    ( 5466): Searching for 'java_interop_jnienv_throw'.
11-12 11:01:08.374 D/Mono    ( 5466): Probing 'java_interop_jnienv_throw'.
11-12 11:01:08.374 D/Mono    ( 5466): Found as 'java_interop_jnienv_throw'.
11-12 11:01:09.489 E/mono    ( 5466): 
11-12 11:01:09.489 E/mono    ( 5466): Unhandled Exception:
11-12 11:01:09.489 E/mono    ( 5466): Android.Gms.Common.Apis.ApiException: 1000: 
11-12 11:01:09.489 E/mono    ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.489 E/mono    ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.489 E/mono    ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.489 E/mono    ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.489 E/mono    ( 5466):   at Plugin.Geofencing.GeofencingImplementation+<StartMonitoring>d__10.MoveNext () [0x000f0] in <aa9ff56f4a7a4b72b03925c3bf41ed1d>:0 
11-12 11:01:09.489 E/mono    ( 5466): --- End of stack trace from previous location where exception was thrown ---
11-12 11:01:09.489 E/mono    ( 5466):   at (wrapper dynamic-method) System.Object.38(intptr,intptr)
11-12 11:01:09.489 E/mono    ( 5466):   --- End of managed Android.Gms.Common.Apis.ApiException stack trace ---
11-12 11:01:09.489 E/mono    ( 5466): com.google.android.gms.common.api.ApiException: 1000: 
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.common.internal.zzb.zzx(Unknown Source:14)
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.common.internal.zzbj.zzy(Unknown Source:0)
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.common.internal.zzbk.zzq(Unknown Source:32)
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.common.api.internal.zzs.zzc(Unknown Source:46)
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.common.api.internal.zzs.setResult(Unknown Source:40)
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.location.LocationServices$zza.setResult(Unknown Source:2)
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.internal.zzbzv.zza(Unknown Source:22)
11-12 11:01:09.489 E/mono    ( 5466):   at com.google.android.gms.internal.zzbzj.onTransact(Unknown Source:22)
11-12 11:01:09.489 E/mono    ( 5466):   at android.os.Binder.execTransact(Binder.java:675)
11-12 11:01:09.489 E/mono    ( 5466): 
11-12 11:01:09.528 D/Mono    ( 5466): GC_BRIDGE waiting for bridge processing to finish
11-12 11:01:09.548 I/zygote64( 5466): Explicit concurrent copying GC freed 4872(791KB) AllocSpace objects, 9(180KB) LOS objects, 91% free, 1197KB/13MB, paused 335us total 21.486ms
11-12 11:01:09.550 D/Mono    ( 5466): GC_TAR_BRIDGE bridges 103 objects 4378 opaque 2115 colors 103 colors-bridged 103 colors-visible 103 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.14ms tarjan 4.97ms scc-setup 0.10ms gather-xref 0.01ms xref-setup 0.03ms cleanup 0.31ms
11-12 11:01:09.551 D/Mono    ( 5466): GC_BRIDGE: Complete, was running for 24.37ms
11-12 11:01:09.551 D/Mono    ( 5466): GC_MINOR: (Nursery full) time 31.28ms, stw 33.35ms promoted 963K major size: 3216K in use: 2457K los size: 2048K in use: 916K
11-12 11:01:09.551 E/mono-rt ( 5466): [ERROR] FATAL UNHANDLED EXCEPTION: Android.Gms.Common.Apis.ApiException: 1000: 
11-12 11:01:09.551 E/mono-rt ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.551 E/mono-rt ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.551 E/mono-rt ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.551 E/mono-rt ( 5466):   at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0 
11-12 11:01:09.551 E/mono-rt ( 5466):   at Plugin.Geofencing.GeofencingImplementation+<StartMonitoring>d__10.MoveNext () [0x000f0] in <aa9ff56f4a7a4b72b03925c3bf41ed1d>:0 
11-12 11:01:09.551 E/mono-rt ( 5466): --- End of stack trace from previous location where exception was thrown ---
11-12 11:01:09.551 E/mono-rt ( 5466):   at (wrapper dynamic-method) System.Object.38(intptr,intptr)
11-12 11:01:09.551 E/mono-rt ( 5466):   --- End of managed Android.Gms.Common.Apis.ApiException stack trace ---
11-12 11:01:09.551 E/mono-rt ( 5466): com.google.android.gms.common.api.ApiException: 1000: 
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.common.internal.zzb.zzx(Unknown Source:14)
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.common.internal.zzbj.zzy(Unknown Source:0)
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.common.internal.zzbk.zzq(Unknown Source:32)
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.common.api.internal.zzs.zzc(Unknown Source:46)
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.common.api.internal.zzs.setResult(Unknown Source:40)
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.location.LocationServices$zza.setResult(Unknown Source:2)
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.internal.zzbzv.zza(Unknown Source:22)
11-12 11:01:09.551 E/mono-rt ( 5466):   at com.google.android.gms.internal.zzbzj.onTransact(Unknown Source:22)
11-12 11:01:09.551 E/mono-rt ( 5466):   at android.os.Binder.execTransact(Binder.java:675)
11-12 11:01:09.551 E/mono-rt ( 5466): 

I am not sure if the problems is something about a permission/config, or the plugin, and if so, how can I solve it.

Currently I check for permissions and if gps is enabled using the following code:

    var permissionsGranted = await CrossGeofencing.Current.RequestPermission();
                if (!permissionsGranted.ToString().Equals("Granted"))
//do something                    
return;
                if (!IsLocationAvailable())
                {
//do something
                    return;
                }

IsLocationAvailable function:

public bool IsLocationAvailable()
        {
            if (!CrossGeolocator.IsSupported)
                return false;
            if (!CrossGeolocator.Current.IsGeolocationEnabled)
                return false;
            if (!CrossGeolocator.Current.IsGeolocationAvailable)
                return false;
            if (!CrossGeofencing.IsSupported)
                return false;
            return true;
        }

Any advice will be appreciated! Thanks


回答1:


1000 = GEOFENCE_NOT_AVAILABLE

You need latest the GPS_PROVIDER and the NETWORK_PROVIDER for GeoFencing to work as it has to detect your location in various locations, including inside or if you are "GPS shaded".

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

There are number of StackOverflow questions/answers concerning this, you can search for

Example of how to check if those services are available: https://stackoverflow.com/a/22793662/4984832



来源:https://stackoverflow.com/questions/53267322/geofence-for-xamarin-crossplatform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!