Hi KG, I am in a similar situation of that of yours. Even after two years I couldn't get a correct answer for this issue. I have posted this issue in this link, http://stackoverflow.com/questions/12586941/onactivityresult-called-prematurely-with-settings-menu
If you have found out the answer, could you please share it with me? Thanks in Advance! Aswathy P Krishnan (DroidBee APK) On Saturday, August 14, 2010 12:15:34 AM UTC+5:30, KG wrote: > > Yeah while looking through WifiManager and ConnectivityManager I saw > those methods. However, I don't want to enable it automatically > because the user probably disabled it for a reason. I think it is > better to give them a choice rather than just go ahead and do it. In > addition, I think I should let them choose to either enable their 3G > (if they have it) or Wifi and configure the settings before forcing > them to use my app. > > On Aug 13, 11:18 am, Kostya Vasilyev <[email protected]> wrote: > > Not quite a direct answer to your question, but: > > > > An "ordinary" Android application can enable Wifi subsystem if not > > already enabled. This requires a special permission. Look up > > WifiManager.setWifiEnabled(). > > > > After enabling Wifi, you can watch broadcast actions defined in > > WifiManager or ConnectivityManager to know when a connection is > established. > > > > -- Kostya > > > > 13.08.2010 22:02, KG пишет: > > > > > > > > > Hi Everyone, > > > > > My app requires a network connection so if they don't have one enabled > > > I prompt them to start it. I do this by calling the Wireless& > > > Network settings Activity as such: > > > > > startActivityForResult(new > > > Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS), > > > NETWORK_RESULT); > > > > > However, when I run my app in the debugger, onActivityResult is called > > > immediately as my calling activity is exited when it should be called > > > once the settings menu if exited. This premature call also sends a > > > resultCode of Activity.RESULT_CANCEL. Here is the code from > > > onActivityResult: > > > > > if (resultCode == Activity.RESULT_OK) { > > > switch (requestCode) { > > > case NETWORK_RESULT: > > > if (!mobileInfo.isConnected()&& > !wifiInfo.isConnected()) > > > noNetwork(); > > > else > > > do_something(); > > > } > > > } > > > > > Does anyone know if I'm doing something wrong? If I understand this > > > correctly, onActivityResult should be the callback to when the > > > Wireless& Network Settings activity exits. > > > > -- > > Kostya Vasilev -- WiFi Manager + pretty widget -- > http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

