Xamarin跨平台地理围栏

时间:2018-11-12 17:35:36

标签: android xamarin gps geofencing location-provider

我目前从DevEddy为xamarin实现了地理围栏插件(之所以使用它,是因为它有一个示例项目,并且它是最近更新的)。并且可以正常工作。

问题: 当我将android位置模式/提供商设置设置为“仅使用GPS(仅设备)”而不是gps,wifi,移动网络并运行我的应用程序时,它会中断,并发送以下错误:

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

整个输出:

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): 

我不确定问题是否出在权限/配置或插件上,如果是,该如何解决。

当前,我使用以下代码检查权限以及是否启用了gps:

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

IsLocationAvailable函数:

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;
        }

任何建议将不胜感激! 谢谢

1 个答案:

答案 0 :(得分:1)

1000 = GEOFENCE_NOT_AVAILABLE

您需要最新的GPS_PROVIDER和NETWORK_PROVIDER for GeoFencing才能工作,因为它必须检测您在各个位置的位置,包括内部或是否被GPS遮挡。

  

公共静态最终int GEOFENCE_NOT_AVAILABLE

     

Geofence服务现在不可用。通常,这是因为用户在“设置”>“位置访问”中关闭了位置访问。

     

常数:1000

与此有关的StackOverflow问题/答案很多,您可以搜索

如何检查这些服务是否可用的示例: https://stackoverflow.com/a/22793662/4984832