wifi ve 3g lokasyon alma
merhabalar wifi ve hücre yayınıyla konum almaya çalısıyorum programım onProviderDisabled metoduna düşüyor OnLocationChangeye gitmiyor.Ayrıca wifi ile cell ile lokasyon alırken gps ide açmak zorundamıyız GPS'i acmazsam Network provider bana false dönüyor
[code]
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
//android.net.NetworkInfo
NetworkInfo wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
Log.e("WIFI", wifi.toString());
Log.e("MOBILE", mobile.toString());
if(wifi.isAvailable() || wifi.getDetailedState() == DetailedState.CONNECTED)
{
//locationProvider = LocationManager.NETWORK_PROVIDER;
llocation=locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER,interval, 0, this.locationListener);
} else //check if it is a tablet without 3G connection
if(mobile!=null){
if(mobile.isAvailable() && mobile.getDetailedState() == DetailedState.CONNECTED)
// locationProvider = LocationManager.PASSIVE_PROVIDER;
llocation=locationManager.getLastKnownLocation(locationManager.PASSIVE_PROVIDER);
updateWithNewLocation(location);
locationManager.requestLocationUpdates(locationManager.PASSIVE_PROVIDER,interval, 0, this.locationListener);
}
[/code]
[code] LİSTENER metodum
public void updateWithNewLocation(Location location) {
locationListener = new android.location.LocationListener() {
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onLocationChanged(Location location)
{
lat = location.getLatitude();
lng = location.getLongitude();
Log.e("lat : ", "" + lat);
Log.e("lng : ", "" + lng);
SimpleDateFormat dateFormat = new SimpleDateFormat( "dd/MM/yyyy HH:mm:ss");
Calendar cal = Calendar.getInstance();
String time_str = dateFormat.format(cal.getTime());
String[] s = time_str.split(" ");
tarih=s[0];
saat=s[1];
Log.e("hkjl => ","" + tarih);
Log.e("aa => ","" + saat);
new ToastMessageTask().execute("");
}
@Override
public void onProviderDisabled(String provider) {
Log.e("onProviderDisabled : ", "onProviderDisabled");
}
@Override
public void onProviderEnabled(String provider)
{
Log.e("onProviderEnabled : ", "onProviderEnabled");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.e("onStatusChanged : ", "onStatusChanged");
}
};
}
[/code]