我遵循了如何检查是否存在 GPS 传感器?
并据此进行了更改,但在所有情况下我的应用程序都崩溃了。我用了
PackageManager pm = getPackageManager();
boolean hasGps = pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
然后我再次修改了我的代码并使用了
LocationManager lm = (LocationManager)getSystemService(LOCATION_SERVICE);
if (lm.getProvider(LocationManager.GPS_PROVIDER) == null) {
Toast.makeText(getApplicationContext(),
"GPS sensor is not available", Toast.LENGTH_LONG).show();
}
但在这两种情况下,我的应用程序都会崩溃。请告诉我我哪里错了?