无法获得三星Galaxy Tab 2&注意

时间:2013-04-19 00:15:44

标签: android samsung-mobile android-location

我使用此代码获取位置:

final LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        final Criteria locationCritera = new Criteria();
        locationCritera.setAccuracy(Criteria.ACCURACY_COARSE);
        locationCritera.setAltitudeRequired(false);
        locationCritera.setBearingRequired(false);
        locationCritera.setCostAllowed(true);
        locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT);

        final String providerName = locationManager.getBestProvider(locationCritera, true);

        if (providerName != null && locationManager.isProviderEnabled(providerName)) {
            locationManager.requestLocationUpdates(providerName, 20000, 100, this);
        } else {
            Toast.makeText(this, "GPS turned off!", Toast.LENGTH_LONG).show();
            final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }

在清单中定义了ACCESS_FINE_LOCATION和ACCESS_COARSE_LOCATION权限。

网络和网络GPS已打开,但我只能使用param“network”(一次)调用ProviderEnabled。但是相同的代码在4.0模拟器上工作正常。昂达4.1标签。 为什么呢?

1 个答案:

答案 0 :(得分:1)

我有一个GPS示例。也许你可以用它作为参考: 示例是here