I try to use the NETWORK_PROVIDER to locate myself. When I run my application (on the emulator with eclipse and with my phone), I always detect the provider as disabled.
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// refresh button
this.b1 = (Button)findViewById(R.id.b1);
this.b1.setOnClickListener(this);
this.lm = (LocationManager)getSystemService(LOCATION_SERVICE);
String provider = LocationManager.NETWORK_PROVIDER;
Location location = this.lm.getLastKnownLocation(provider);
this.t1 = (TextView)findViewById(R.id.t1);
if (location != null)
this.t1.setText(location.toString());
else
if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)==false)
this.t1.setText("Provider disabled");
else
this.t1.setText("No location, please wait");
int t = 5000;
int distance = 5;
lm.requestLocationUpdates(provider, t, distance, myLocationListener);
}
public void onClick(View view){
Location location = this.lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null)
this.t1.setText(location.toString());
else
this.t1.setText("Refreshed but no location");
}
I checked, the option in Settings > Location > Use wireless networks is enabled.
edit: code corrected as mentioned by NickT but still receive no location when pushing the button
I think you meant to write
didn’t you?
As it stands you display ‘disabled’ when it’s enabled.