第一个对不起我的英语我理解得很好但不会写好吗?
我有一个 LocationService 可以保存纬度和经度。他工作得很好,但我想在 LocationListener 更改时向我的意图发送信息。我想向我的意图发送一个字符串以放入 EditText。
服务代码:
public class LocalizadorService extends Service{
private LocationManager locManager;
private LocationListener locListener;
private EjercicioBD baseDatos = EjercicioBD.getEjercicioBD(this);
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
encontrarGPS();
super.onStart(intent, startId);
}
@Override
public void onDestroy() {
locManager.removeUpdates(locListener);
super.onDestroy();
}
private void encontrarGPS() {
//Obtenemos una referencia al LocationManager
locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if(locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
locListener = new LocationListener(){
public void onLocationChanged(Location arg0) {
if (arg0 != null) {
setCurrentLocation(arg0);
}
}
public void onProviderDisabled(String arg0) {
noGPS();
Toast.makeText(LocalizadorService.this, "El GPS ha sido desactivado, activelo", Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String arg0) {
**HERE WANT TO SEND A STRING TO MY INTENT**
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
**HERE WANT TO SEND A STRING TO MY INTENT**
}
};
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 7000, 0, locListener);
}
else{
Toast.makeText(LocalizadorService.this, "El GPS no esta activado, por favor activelo para empezar", Toast.LENGTH_SHORT).show();
noGPS();
}
}
private void noGPS(){
Intent intent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
private void setCurrentLocation(Location arg0){
if(arg0 != null)
baseDatos.insertarTablas(arg0.getLatitude(), arg0.getLongitude(), arg0.getSpeed());
}
}
我能怎么做?
谢谢大家。