Wireless settings dialog

2019-06-02 16:19发布

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条回答
Fickle 薄情
2楼-- · 2019-06-02 16:46

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().

查看更多
登录 后发表回答