我的英语第一个抱歉我理解不错,但不写好吗?沟通服务的意图
我有一个LocationService,它保存在bd纬度和纵向。他运作良好,但我想在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());
}
}
我该怎么办?
谢谢大家。
谢谢,现在运行良好,但我的服务延伸服务,因为如果我扩展IntentService不起作用。感谢所有的时间。 – monchyrcg