8

我正在研究 GPS 部分和标准,我可以将精度设置为 ACCURACY_FINE、ACCURACY_MEDIUM 等。但是,由于某种原因,如果我将标准设置为 ACCURACY_HIGH,我会不断收到强制关闭错误。关于可能导致它的任何想法?

这是我的清单,我很确定一切都很好,因为我可以使用不同的标准:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />

这是我的日志:

 07-05 08:51:48.641: W/dalvikvm(1040): threadid=1: thread exiting with uncaught exception (group=0x40015578)
 07-05 08:51:48.657: E/AndroidRuntime(1040): FATAL EXCEPTION: main
 07-05 08:51:48.657: E/AndroidRuntime(1040): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jetdelivery.mobile/com.jetdelivery.mobile.statuspage}: java.lang.IllegalArgumentException: accuracy=3
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.os.Handler.dispatchMessage(Handler.java:99)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.os.Looper.loop(Looper.java:130)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.app.ActivityThread.main(ActivityThread.java:3687)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at java.lang.reflect.Method.invokeNative(Native Method)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at java.lang.reflect.Method.invoke(Method.java:507)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at dalvik.system.NativeStart.main(Native Method)
 07-05 08:51:48.657: E/AndroidRuntime(1040): Caused by: java.lang.IllegalArgumentException: accuracy=3
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.location.Criteria.setAccuracy(Criteria.java:223)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at com.jetdelivery.mobile.statuspage.onCreate(statuspage.java:125)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
 07-05 08:51:48.657: E/AndroidRuntime(1040):    ... 11 more

我正在使用 Android 2.3.5 固件进行开发。谢谢!

4

3 回答 3

21

android Criteria有两组不同的精度常数。ACCURACY_FINEACCURACY_COARSE用于一般位置,而ACCURACY_LOWACCURACY_MEDIUMACCURACY_HIGH“可用于水平、高度、速度或方位精度。” 如果您在谈论一般 GPS 位置,您应该使用粗略或精细。

于 2012-07-05T16:02:19.470 回答
18

为了更清楚地说明 matt5784 的答案,这里有一个如何使用新常量的示例:

    //All your normal criteria setup
    Criteria criteria = new Criteria();
    //Use FINE or COARSE (or NO_REQUIREMENT) here
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(true);
    criteria.setSpeedRequired(true);
    criteria.setCostAllowed(true);
    criteria.setBearingRequired(true);

    //API level 9 and up
    criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
    criteria.setBearingAccuracy(Criteria.ACCURACY_LOW);
    criteria.setSpeedAccuracy(Criteria.ACCURACY_MEDIUM);
于 2013-05-08T11:23:54.740 回答
2

ACCURACY_FINE分别ACCURACY_COARSE用常数值 1 和 2 分组。ACCURACY_LOW,MEDIUMHIGH与常数值 1、2 和 3 组合在一起。

似乎 setAccuracy 期望并返回COARSEor ,而 setVerticalAccuracy、setHorizo​​ntalAccuracy 、FINEsetSpeedAccuracy 和 setBearingAccuracy 期望or 。此外,当您调用 setAccuracy 时,它会像这样设置水平精度:LOWMEDIUMHIGH

public void setAccuracy(int accuracy) {
    if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_COARSE) {
        throw new IllegalArgumentException("accuracy=" + accuracy);
    }
    if (accuracy == ACCURACY_FINE) {
        mHorizontalAccuracy = ACCURACY_HIGH;
    } else {
        mHorizontalAccuracy = ACCURACY_LOW;
    }
}

所以,使用ACCURACY_FINE. 我同意这应该得到更好的记录。

于 2013-11-11T20:41:52.280 回答