android - How can I get a WifiManager Object inside of a Service? -


i'm writing app android spawns service periodically checks wifi state , changes based on conditions. problem whenever try create wifimanager object check state of wifi (and perhaps control it), gives me uninitialized object. here code:

public class wificheckerservice extends service {      // service code , run() method      private void checkwifi() {         wifimanager wifi = (wifimanager) getsystemservice(context.wifi_service);         system.out.println(wifi.getconnectioninfo());         // rest of code     } } 

and here line in log when gets code.

02-18 05:22:59.274: info/system.out(1170): ssid: <none>, bssid: <none>, mac: <none>, supplicant state: uninitialized, rssi: -200, link speed: -1, net id: -1 

obviously i'm not getting system wifimanager object. know has fact in service thread, still having trouble understanding concept , little explanation why it's not working , how can fix appreciated.

(on sort of unrelated note, think explanation explain why can't use line toast.maketext(getbasecontext(), "checking wifi...", toast.length_short).show(); in service)

have enabled wifi on device?

if wifi not enabled, show uninitialzed output.

i tried code , works fine wifi enabled:

wifimanager wifi = (wifimanager) getsystemservice(context.wifi_service);                 wifiinfo w = wifi.getconnectioninfo();                 log.d(log_tag, w.tostring()); 

logcat:

e/wpa_supplicant( 4337): wpa_driver_priv_driver_cmd failed e/wpa_supplicant( 4337): wpa_driver_priv_driver_cmd failed w/activitymanager( 1332): activity idle timeout historyrecord{454624f8 com.xxx.xxx/.ui.somescreen} d/somescreen( 4365): ssid: <none>, bssid: <none>, mac: 00:26:e8:b7:d2:e0, supplicant state: dormant, rssi: -200, link speed: 54, net id: -1 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -