java - how to display a button upon wifi gets connected? -


in application i'm connecting wifi programatically. there way me display button upon wifi gettting connected?

you need implement broadcastreceiver listen network state changes.

private final broadcastreceiver mwifiscanreceiver = new broadcastreceiver() {     @override     public void onreceive(context c, intent intent) {         if (intent.getaction() == wifimanager.network_state_changed_action) {             bundle extras = intent.getextras();             networkinfo ni = extras.get(extra_network_info);             if (ni.getstate() == state.connected) {                 //show button             } else {                 //hide button             }         } else if (intent.getaction() == wifimanager.supplicant_connection_change_action) {             bundle extras = intent.getextras();             supplicantstate ss = extras.get(extra_new_state);             if (ss.getstate() == completed) {                 //show button, note may not have ip address yet             } else {                 //hide button             }             supplicantstate.completed         }     } }; 

and, somewhere in oncreate() method of activitys display button:

mwifimanager = (wifimanager)getsystemservice(context.wifi_service);  //to listen network state changes (cell , wifi) registerreceiver(mwifiscanreceiver, new intentfilter(wifimanager.network_state_changed_action));  //to listen wifi changes registerreceiver(mwifiscanreceiver, new intentfilter(wifimanager.supplicant_connection_change_action)); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -