从昨天开始广泛搜索,找不到有这个问题的人:
我创建了一个 GPS 检查函数,它只返回 true 或 false 指示 GPS 是否打开。这在模拟器上的 android 2.2 和 4.1 以及运行 4.1 的手机上运行良好。
功能如下:
private Boolean checkGPSEnabled(){
try{
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.toLowerCase().contains("gps")){
return true;
}
}
catch(IllegalArgumentException e){
return true;
}
return false;
}
问题是,当在 Android 模拟器上执行此检查时启用 GPS 时,模拟器会彻底崩溃。
以下是发生错误时在 LogCat 中打印的内容:
10-12 15:23:45.593: W/dalvikvm(899): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
10-12 15:23:45.644: E/AndroidRuntime(899): FATAL EXCEPTION: main
10-12 15:23:45.644: E/AndroidRuntime(899): java.lang.IllegalStateException: Could not execute method of the activity
10-12 15:23:45.644: E/AndroidRuntime(899): at android.view.View$1.onClick(View.java:3591)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.view.View.performClick(View.java:4084)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.view.View$PerformClick.run(View.java:16966)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.os.Handler.handleCallback(Handler.java:615)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.os.Handler.dispatchMessage(Handler.java:92)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.os.Looper.loop(Looper.java:137)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-12 15:23:45.644: E/AndroidRuntime(899): at java.lang.reflect.Method.invokeNative(Native Method)
10-12 15:23:45.644: E/AndroidRuntime(899): at java.lang.reflect.Method.invoke(Method.java:511)
10-12 15:23:45.644: E/AndroidRuntime(899): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-12 15:23:45.644: E/AndroidRuntime(899): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-12 15:23:45.644: E/AndroidRuntime(899): at dalvik.system.NativeStart.main(Native Method)
10-12 15:23:45.644: E/AndroidRuntime(899): Caused by: java.lang.reflect.InvocationTargetException
10-12 15:23:45.644: E/AndroidRuntime(899): at java.lang.reflect.Method.invokeNative(Native Method)
10-12 15:23:45.644: E/AndroidRuntime(899): at java.lang.reflect.Method.invoke(Method.java:511)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.view.View$1.onClick(View.java:3586)
10-12 15:23:45.644: E/AndroidRuntime(899): ... 11 more
10-12 15:23:45.644: E/AndroidRuntime(899): Caused by: java.lang.IllegalArgumentException: requested provider network doesn't exisit
10-12 15:23:45.644: E/AndroidRuntime(899): at android.os.Parcel.readException(Parcel.java:1429)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.os.Parcel.readException(Parcel.java:1379)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.location.LocationManager._requestLocationUpdates(LocationManager.java:660)
10-12 15:23:45.644: E/AndroidRuntime(899): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:482)
10-12 15:23:45.644: E/AndroidRuntime(899): at com.desmill.taxi.activity.TaxiCaller.callTaxi(TaxiCaller.java:52)
10-12 15:23:45.644: E/AndroidRuntime(899): ... 14 more
有任何想法吗?我如何让它显示它所说的其他错误...14 more...?谢谢!