locked
[wp8.1]How to enable Internet? RRS feed

  • Question

  • Hi

      In my app there is scenario like,

    Check if internet(wifi/mobile data) is enabled.

    If enabled then move to Page2.

    If internet is not enabled ,then enable the internet(wifi/mobile data) with no confirmation from user and move to Page2.

    How to acheive this?code Pls.

    Saturday, November 21, 2015 12:16 PM

Answers

  • >>Check if internet(wifi/mobile data) is enabled.

    You could use the NetworkInformation class to detect whether an internet connection is available as suggested here: http://stackoverflow.com/questions/14908559/how-to-determine-if-internet-connection-is-available

    >>If internet is not enabled ,then enable the internet(wifi/mobile data) with no confirmation from user and move to Page2.
    >>How to acheive this?

    This is not possible. A Windows Store App runs in a sandboxed environment and cannot make an internet connection available on behalf of the user. This is not permitted for security reasons.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Fred Bao Monday, November 23, 2015 3:28 AM
    • Marked as answer by Fred Bao Wednesday, December 2, 2015 11:38 AM
    Saturday, November 21, 2015 4:54 PM

All replies

  • detecting internet connectivity:

    // will return true if there is an internet connecitivity : wifi or cellular (3g/4g)
    bool IsConnectedToInternet()
    {
    	var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
    	if (connectionProfile == null)
    		return false;
    		
    	return connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
    }

    if internet is off what you can do is ask the user to connect or you can show him the settings page for that.

    You can't do it for him.

    example:

    await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-wifi:"));

    • Proposed as answer by Fred Bao Monday, November 23, 2015 3:28 AM
    Saturday, November 21, 2015 1:00 PM
  • >>Check if internet(wifi/mobile data) is enabled.

    You could use the NetworkInformation class to detect whether an internet connection is available as suggested here: http://stackoverflow.com/questions/14908559/how-to-determine-if-internet-connection-is-available

    >>If internet is not enabled ,then enable the internet(wifi/mobile data) with no confirmation from user and move to Page2.
    >>How to acheive this?

    This is not possible. A Windows Store App runs in a sandboxed environment and cannot make an internet connection available on behalf of the user. This is not permitted for security reasons.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Fred Bao Monday, November 23, 2015 3:28 AM
    • Marked as answer by Fred Bao Wednesday, December 2, 2015 11:38 AM
    Saturday, November 21, 2015 4:54 PM