1

我正在测试一个应用程序,它选择当前位置,并在一个小部件上进行筛选。我正在使用此功能,但是当我尝试将精度更改为 HIGH 时,一切都崩溃了!

    private void startListening(){
        AppLog.logString("Service.startListening()");

        final Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);

        final String bestProvider = manager.getBestProvider(criteria, true);

        if (bestProvider != null && bestProvider.length() > 0) {
            manager.requestLocationUpdates(bestProvider, 500, 10, listener);
        }
        else {
            final List<String> providers = manager.getProviders(true);

            for (final String provider : providers) {
                manager.requestLocationUpdates(provider, 500, 10, listener);
            }
        }
    }
4

1 回答 1

1

Add this to your AndroidManigest.xml file:

   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
于 2012-07-14T15:26:27.040 回答