Wireless settings dialog

萝らか妹 提交于 2019-12-08 06:19:30

问题


i am checking networking connection using the below code:

public static boolean haveInternet(Context ctx) 
{
    NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

   if (info == null || !info.isConnected()) {
          return false;  // no connection
   }

  return true;   // true if having connection
}       

Now, on "no connection" , i am launching "Wireless settings" dialog using the below code:

    context.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));

Here, user is being able to "on/off" the wireless, now how do i come to know whether the user has made "on" the wi-fi or not? i.e. what result is returned by the above intent on the successful wireless connection. how do i check it ?

I think i need to call startActivityForResult method, but dont know how do i do it ?

Update:

I want to do same way as http://groups.google.is/group/android-developers/msg/6874a5e4675dffdb


回答1:


now how do i come to know whether the user has made "on" the wi-fi or not? i.e. what result is returned by the above intent on the successful wireless connection. how do i check it ?

There is no result. You check it by calling the code you have shown above, or by monitoring relevant broadcast Intents (see ConnectivityManager and its CONNECTIVITY_ACTION or WifiManager and its WIFI_STATE_CHANGED_ACTION or NETWORK_STATE_CHANGED_ACTION).

I think i need to call startActivityForResult method, but dont know how do i do it ?

That activity does not support startActivityForResult().



来源:https://stackoverflow.com/questions/3889241/wireless-settings-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!