• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help Get current location of user without using gps or internet but by using Network_Provider in android

  • Thread starter Thread starter Android Question
  • Start date Start date
A

Android Question

Guest
This question is directly related to the same prevailing stackoverflow question at "Android: get current location of user without using gps or internet" where the accepted answer is actually not answering the question. I should be able to get the location of the device via network provider not with GPS or internet. Following is the accepted answer in that question. (The following code parts should be included in the onCreate() method)

// Acquire a reference to the system Location ManagerLocationManager locationManager =(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updatesLocationListener locationListener =newLocationListener(){publicvoid onLocationChanged(Location location){// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);}

publicvoid onStatusChanged(String provider,int status,Bundle extras){}

publicvoid onProviderEnabled(String provider){}

publicvoid onProviderDisabled(String provider){}};

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0, locationListener);

I changed the above code given in the linked answer as following but no success.

protectedvoid onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);finalTextView txtView =(TextView) findViewById(R.id.tv1);
txtView.setText("ayyo samitha");////

// Acquire a reference to the system Location ManagerLocationManager locationManager;
locationManager=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);

// Define a listener that responds to location updatesLocationListener locationListener =newLocationListener(){publicvoid onLocationChanged(Location location){// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);

}

privatevoid makeUseOfNewLocation(Location location){
txtView.setText("sam came in");
txtView.append(location.toString());}

publicvoid onStatusChanged(String provider,int status,Bundle extras){}

publicvoid onProviderEnabled(String provider){// makeUseOfNewLocation(location);}

publicvoid onProviderDisabled(String provider){}};

// Register the listener with the Location Manager to receive location updatesif(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0, locationListener);}

}

How to accomplish what I want by correcting above code or any other method? Can somebody please help me.
 
Back
Top Bottom