android - Is there a better way to do this ? Checking periodically hot spot creation status -


in android application creating(code shown below) hot spot(access point) on load of application purpose has remain active throughout life cycle of application(i know has disadvantages), now, how can make sure remains active throughout ? idea have run timer checks method.getname().equals("setwifiapenabled") status , determines if inactive ? there better way indication when ap disabled ?

  intentfilter filter = new intentfilter();     filter.addaction(wifimanager.supplicant_connection_change_action);     filter.addaction(wifimanager.supplicant_state_changed_action);     filter.addaction(wifimanager.extra_new_state);     filter.addaction(wifimanager.extra_supplicant_connected);     registerreceiver(wifieventreceiver, filter);   private broadcastreceiver wifieventreceiver = new broadcastreceiver() {     private boolean enabled = false;      @override     public void onreceive(context context, intent intent) {         system.out.println ("wifi event broadreceiver:onreceive()=======================================");         if(intent.getaction().equals(wifimanager.supplicant_state_changed_action)) {             system.out.println("===== supplicant_state_change_action event happened....");             intent.getbooleanextra(wifimanager.extra_supplicant_connected, false);         }     } };  private void createwifiaccesspoint() {     if(wifimanager.iswifienabled())     {         wifimanager.setwifienabled(false);               }            method[] wmmethods = wifimanager.getclass().getdeclaredmethods();   //get declared methods in wifimanager class          boolean methodfound=false;     for(method method: wmmethods){         if(method.getname().equals("setwifiapenabled")){             methodfound=true;             wificonfiguration netconfig = new wificonfiguration();             netconfig.ssid = ssid;              netconfig.allowedauthalgorithms.set(wificonfiguration.authalgorithm.open);             try {                 boolean apstatus=(boolean) method.invoke(wifimanager, netconfig,true);                           (method iswifiapenabledmethod: wmmethods)                 {                     if(iswifiapenabledmethod.getname().equals("iswifiapenabled")){                         while(!(boolean)iswifiapenabledmethod.invoke(wifimanager)){                         };                         for(method method1: wmmethods){                             if(method1.getname().equals("getwifiapstate")){                                 int apstate;                                 apstate=(integer)method1.invoke(wifimanager);                             }                         }                     }                 }                 if(apstatus)                 {                     log.d("splash activity", "access point created");                    }else                 {                     log.d("splash activity", "access point creation failed");                    }              } catch (illegalargumentexception e) {                 e.printstacktrace();             } catch (illegalaccessexception e) {                 e.printstacktrace();             } catch (invocationtargetexception e) {                 e.printstacktrace();             }         }           }     if(!methodfound){         log.d("splash activity", "your phone's api not contain setwifiapenabled method configure access point");     } }         

it seems have register broadcastreceiver intent supplicant_state_changed_action or supplicant_connection_change_action

i assume know registering receivers.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -