Wireless settings dialog
Asked Answered
T

1

1

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

Triptych answered 8/10, 2010 at 9:22 Comment(1)
Hi Sir, facing same problem, I am using BroadcastReceiver to check if user has enabled Wifi, then download should start, but my receiver never gets call. I am not getting where do need to call sendBroadcast().Histo
R
2

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

Rome answered 8/10, 2010 at 12:4 Comment(8)
@Rome thanx for the support, but how do i monitor the broadcast intents? i dont know about it, pls let me knowTriptych
@Paresh Mayani: Register a BroadcastReceiver on an IntentFilter to watch for those actions. If only your activity cares about the changes, have it call registerReceiver() to register a BroadcastReceiver -- but be sure to call unregisterReceiver() at a later point. For example, here is an application that watches for the ACTION_BATTERY_CHANGED broadcast: github.com/commonsguy/cw-advandroid/tree/master/SystemEvents/…Rome
@Rome i am really stucked because if there is having a connection, then i am fetching xml from the URL and if not (i.e. else), i am showing dialog, now dialog let you for the wireless settings, where i can set the wifi on/off , once i on/off the wi-fi , i returned back to the original activity by pressing "Back" button, now "connection" is available show it should fetch the xml, pls show me a way, plsTriptych
@Rome i dont know anything about broadcast intentTriptych
@Paresh Mayani: developer.android.com/reference/android/content/… developer.android.com/guide/topics/fundamentals.html#appcompRome
@Paresh Mayani: Plus, there is the example app I linked to previously: github.com/commonsguy/cw-advandroid/tree/master/SystemEvents/…Rome
@Rome i found one link where broadcast related stuff are given: #2295471 , are you talking about this, right ?Triptych
@Paresh Mayani: That is one way of doing it, though probably not the way you want. That puts the BroadcastReceiver in the manifest, which means you will get the broadcasts whenever they occur, regardless of whether your activity is running. In your case, I would think you would only care about the broadcasts while your activity is in use, in which case the sample application that I linked to (twice) is a more appropriate model.Rome

© 2022 - 2024 — McMap. All rights reserved.