|
写了简单的GPS程序, 但是貌似模拟器的GPS没有起来。
onStatusChanged里的arg1一直=1。
Android SDK用的1.5 ADT用的0.9.1
Java code
package com.example.android.gpstest;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
public class GPSTest extends Activity implements LocationListener {
private LocationManager lm;
private List<String> proList;
private Location loc;
private String PROVIDER_NAME = "my_test_provider";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10l, 100l, this);
}
public void onLocationChanged(Location arg0) {
String lat = String.valueOf(arg0.getLatitude());
String lon = String.valueOf(arg0.getLongitude());
Log.e("GPS", "location changed: lat=" + lat + ", lon=" + lon);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Log.e("GPS", "The provider " + provider + " is disabled");
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Log.e("GPS", "The provider " + provider + " is enabled");
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
if (arg1 == 0) {
Log.e("GPS", arg0 + " is OUT OF SERVICE");
} else if (arg1 == 1) {
Log.e("GPS", arg0 + " is TEMPORARILY_UNAVAILABLE");
} else {
Log.e("GPS", arg0 + " is Available");
}
}
} |
|