我的英語第一個抱歉我理解不錯,但不寫好嗎?溝通服務的意圖
我有一個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