概括
我在真实设备上运行此代码,而不是模拟器。
我一直在阅读 Xamarin Monodroid 定位服务教程 -这里
当我编译代码时,我在以下代码行中得到“Java.Lang.IllegalArgumentException” -
protected override void OnResume()
{
base.OnResume();
_locationManager.RequestLocationUpdates(_locationProvider, 0, 0, this);
Log.Debug(LogTag, "Listening for location updates using " + _locationProvider + ".");
}
深入研究异常会发现以下内容 -
Java.Lang.IllegalArgumentException: provider=
at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00023] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:368
at Android.Locations.LocationManager.RequestLocationUpdates (string,long,single,Android.Locations.ILocationListener) [0x0004a] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.Locations.LocationManager.cs:814
at com.xamarin.recipes.getlocation.Activity1.OnResume () [0x0001b] in /Users/SimonGilbert/Downloads/GetLocation/Activity1.cs:86
at Android.App.Activity.n_OnResume (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:2596
at at (wrapper dynamic-method) object.383877df-2ff3-46a8-906d-6d9bd2915e69 (intptr,intptr) <IL 0x00011, 0x0001b>
at
at --- End of managed exception stack trace ---
at java.lang.IllegalArgumentException: provider=
at at android.os.Parcel.readException(Parcel.java:1331)
at at android.os.Parcel.readException(Parcel.java:1281)
at at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
at at android.location.LocationManager._requestLocationUpdates(LocationManager.java:614)
at at android.location.LocationManager.requestLocationUpdates(LocationManager.java:478)
at at com.xamarin.recipes.getlocation.Activity1.n_onResume(Native Method)
at at com.xamarin.recipes.getlocation.Activity1.onResume(Activity1.java:43)
at at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
at at android.app.Activity.performResume(Activity.java:4540)
at at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2437)
at at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2475)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1989)
at at android.app.ActivityThread.access$600(ActivityThread.java:124)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1148)
at at android.os.Handler.dispatchMessage(Handler.java:99)
at at android.os.Looper.loop(Looper.java:137)
at at android.app.ActivityThread.main(ActivityThread.java:4436)
at at java.lang.reflect.Method.invokeNative(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:511)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at at dalvik.system.NativeStart.main(Native Method)
at
问题
- 有没有人见过这个?
- 关于它可能是什么原因的任何想法?
更新
从阅读中,似乎添加以下内容可能会解决我的问题,尽管我还没有机会测试它 -
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
似乎另一种解决方案可能是检查网络提供商是否也可用 -
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 300000, 500, locationListener);
也许还要检查 GPS Provider 是否也可用 -
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 300000, 500, locationListener);
非常感谢。