Search code examples
c#windows-phone-7wifiwindows-phone-7.13g

Forcing app to use 3G connection over wi-fi connection in WP7.5


I have an app in which as soon as user launches the app and ACCEPTS the EULA then the registration process starts, and to finish the registration process to obtain the user_id the app has to hit 3 servers.The first server has connection must happen through 3G even if wi-fi is available the user gets a message to disable Wi-Fi and connect only to 3g network to continue the registration. All the code is in place and the app works fine too. But the new requirement is to ignore the wi-fi and use only 3G so that the user is not disturbed with the message which will need the settings of the phone to be changed.

I went through many forum posts but nothing helped. I found this post and thought i could refer it to use according to my need. But did not help.

Then I found this:-

ConnectState.Disconnected

But i dunno whether i can use this to disable wi-fi till the 1st request is made then enable wi-fi after that.

Please help.

Thank You


Solution

  • Now, why I unmarked the previous post as not answer was, I found a way to force my app to use 3G network connection over Wi-Fi, and the best part is, its going to happen only in the Application level and not device level. And of course the user will be notified that for registration purpose we will be using the 3G network. Here is the code.

    In my httpconnection class post() method. am doing the following before initiating the request.

       HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create(uri);
    //the network preference depends on the requestID
                if (requestId == DataManager.REQ_REGISTRATION)
                {
                    myHttpWebRequest1.SetNetworkPreference(NetworkSelectionCharacteristics.Cellular);
                }
                else
                {
                    myHttpWebRequest1.SetNetworkPreference(NetworkSelectionCharacteristics.NonCellular);
                }
    

    As simple as that. In other scenarios(not in my requirement) where 3G is not mandatory but preferred, the application tries to connect through 3G but if that fails it will automatically (without user's interference) connect through the available network.

    Thanks to Steve for the knowledge he shared. I hope this helps other ppl with similar requirements.