0
我只想接收我从Emulator Control发送的Activity中的位置数据。以下是我用我的主要活动代码:在android中模拟位置数据
public class LocationAlert extends Activity {
TextView txtMessage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtMessage = (TextView)findViewById(R.id.txtMsg);
LocationManager lm = (LocationManager)getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, mLocListener);
if (lm.getLastKnownLocation(LocationManager.GPS_PROVIDER) != null){
txtMessage.setText(String.valueOf(lm.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLatitude()));
}
}
LocationListener mLocListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
if (location != null){
txtMessage.setText("Latitude: " + String.valueOf(location.getLatitude()) + ", Longitude: " + String.valueOf(location.getLongitude()));
}
}
};
}
,但我没有得到任何数据,并在模拟器中运行的所有进程关闭一个接一个,我可以在看设备选项卡。上面的代码有什么问题?
它已经在那里。 – Ali 2011-05-18 10:39:40