Forum Xamarin.Forms

how to check mobile data/wifi enabled on device using xamarin.forms for all platform

Hi,

I am developing Mobile app for all platform using Xamarin.Forms. I need help about checking internet connectivity on device.
Can you please tell me how can we check internet connectivity i.e. Mobile data, wifi on all device, writting common function in Xamarin.Forms.

Thanks in advance!

Best Answer

Answers

  • KrishTalaKrishTala INMember ✭✭

    Thanks Namyslaw for quick suggestion.
    I installed suggested package and implemented same feature with reference of github projects.
    After implementation I caught below error,

    CrossConnectivity.Current.IsConnected = System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

    If you have any idea about this let me know.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @KrishTala have you follow all indication ? The property should exists https://github.com/jamesmontemagno/ConnectivityPlugin#changes-in-connectivity

    it's a runtime error?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @KrishTala said:
    Thanks Namyslaw for quick suggestion.
    I installed suggested package and implemented same feature with reference of github projects.
    After implementation I caught below error,

    CrossConnectivity.Current.IsConnected = System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

    If you have any idea about this let me know.

    Have you installed the package into the platform specific project too?

  • NamyslawSzymaniukNamyslawSzymaniuk USMember ✭✭✭✭

    @lpdavies said:

    @KrishTala said:
    Thanks Namyslaw for quick suggestion.
    I installed suggested package and implemented same feature with reference of github projects.
    After implementation I caught below error,

    CrossConnectivity.Current.IsConnected = System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

    If you have any idea about this let me know.

    Have you installed the package into the platform specific project too?

    Exactly! You need to be sure, that you've installed this nuget, against PCL, as well as platform specific projects (Android, iOS etc.).

  • KrishTalaKrishTala INMember ✭✭

    @NamyslawSzymaniuk said:

    @lpdavies said:

    @KrishTala said:
    Thanks Namyslaw for quick suggestion.
    I installed suggested package and implemented same feature with reference of github projects.
    After implementation I caught below error,

    CrossConnectivity.Current.IsConnected = System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

    If you have any idea about this let me know.

    Have you installed the package into the platform specific project too?

    Exactly! You need to be sure, that you've installed this nuget, against PCL, as well as platform specific projects (Android, iOS etc.).

    I installed nuget against PCL as well as all platform still same issue persist :-(

    below is my code

    public App()
            {
    
                InitializeComponent();
    
                try
                {
                    CurrentApp = this;
                    bool isLoggedIn = Properties.ContainsKey("IsLoggedIn") ? (bool)Properties["IsLoggedIn"] : false;
                    isLoggedIn = false;
    
               //connection status
                    var strConnection = CrossConnectivity.Current.IsConnected ? "Connected" : "No Connection";
    
                    CrossConnectivity.Current.ConnectivityChanged += (sender, args) =>
                    {
    
                        CommonHelper.IsConnected = args.IsConnected;
                        //DisplayAlert("Connectivity Changed", "IsConnected: " + args.IsConnected.ToString(), "OK");
                    };
    
                    // we remember if they're logged in, and only display the login page if they're not
                    if (isLoggedIn)
                        MainPage = new MainPage();
                    else
                        MainPage = new LoginModalPage(this);
                }
                catch (Exception ex)
                {
    
                }
            }
    
  • seanydaseanyda GBMember ✭✭✭✭✭

    What is CommonHelper?

    Comment out the ConnectivityChanged event, Does it crash on this line?

    var strConnection = CrossConnectivity.Current.IsConnected ? "Connected" : "No Connection";

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think is always better you create a prj and post it to GitHub so people can download it and do some debug.

  • KrishTalaKrishTala INMember ✭✭

    Thanks John Hardman & all for giving solution.
    Thanks John for detailed information, package Installed in every project and did same you suggested now its working.
    great and thanks once again to #ALL

Sign In or Register to comment.