我正在做我的最后一个项目,并且是 Android 新手。我想将速度从 LocationManager 传递给 Activity ,我试图用 Intent 传递它,我的意思是 ( Intent j = new Intent(this, CallblockingActivity.class)
) 但它不起作用。请帮帮我。
public class ShowLocationActivity extends Activity {
private TextView latituteField;
private TextView longitudeField;
private TextView speed;
public float a;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationmanager);
latituteField = (TextView) findViewById(R.id.TextView02);
longitudeField = (TextView) findViewById(R.id.TextView04);
speed = (TextView)findViewById(R.id.textspeed);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll);
}
private class mylocationlistener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
float lat = (float) (location.getLatitude());
float lng = (float) (location.getLongitude());
latituteField.setText(String.valueOf(lat));
longitudeField.setText(String.valueOf(lng));
a=location.getSpeed();
speed.setText("current speed" + a);
*** **My problwm is here,I just want to pass a**
Log.d("LOCATION CHANGED", location.getLatitude() + "");
Log.d("LOCATION CHANGED", location.getLongitude() + "");
Toast.makeText(ShowLocationActivity.this,
location.getLatitude() + "" + location.getLongitude(),
Toast.LENGTH_LONG).show();
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
}