我正在使用此代码获取 Android 设备的 GPS 坐标。LocationListener 永远不会触发,我不知道为什么。任何建议,将不胜感激。
public class MyClass extends ListActivity {
private LocationManager locmgr = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
// Start the location manager
locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
} // onCreate
@Override
public void onResume() {
super.onResume();
// grab the location manager service
locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
onLocationChange);
} // onResume
// Start a location listener
LocationListener onLocationChange = new LocationListener() {
public void onLocationChanged(Location loc) {
// This never fires
Toast.makeText(getApplicationContext(), "Test",
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status,
Bundle extras) {}
};
} // end MyClass