Я использую IntentService
и получаю местоположение устройства с помощью LocationManager
. но когда я получаю местоположение, мое местоположение всегда равно нулю. Зачем ? вот мой кодМестоположение null Внутри onHandleIntent()
package com.example.netlogger.Services;
import java.util.ArrayList;
import java.util.Date;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
public class LocationLogService extends IntentService {
SharedPreferences prefs;
LocationManager lm;
Location l;
LocationListener ls = 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) {
// TODO Auto-generated method stub
l = location;
}
};
public LocationLogService() {
super("some name");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("TAGG", "HERE");
prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
lm = (LocationManager) getBaseContext().getSystemService(
LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ls);
l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (l != null) {
Log.d("TAGG", "NOT NULL");
}
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("", "done");
lm.removeUpdates(ls);
}
}
Включена ли она в манифест? –
Да. Все разрешения и компоненты подключены. –
'Network_provider' работает хорошо, но gps не –