1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to ad[email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Internet Connection control with Delphi Xe5

Discussion in 'Delphi Android And IOS' started by AdminDF, Jan 25, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    UPDATE: The project has been updated to include retrieving the current SSID (that the device is connected to). For Android, this means adding the Access Wifi State permission. Refer to the updated text in the article.

    It’s a question that has been asked a few times in the Embarcadero forums: how to check if a mobile device (either Android or iOS) has an internet connection.

    I already knew of a solution for iOS, and recently I came across one for Android, so I figured I would combine the two and create a platform-independent unit, called NetworkState. In that unit, I created an abstract class that could be derived from in other units that would provide the implementation for each platform, i.e. Android and iOS. The declaration for the abstract class TCustomNetworkState looks like this:
    TCustomNetworkState = class(TObject)
    function GetSSID: String; virtual; abstract;
    function IsConnected: Boolean; virtual; abstract;
    function IsWifiConnected: Boolean; virtual; abstract;
    function IsMobileConnected: Boolean; virtual; abstract;
    end;

    As can be seen, the intention is to simply provide functions for checking if either there is a connection at all, and specifically whether there is either a Wifi or Mobile (Cellular data) connection, and what the SSID is. It was also the intention that the implementation use the supported methods for checking for connections, rather than say, using the Indy components.

    The units NetworkState.iOS and NetworkState.Android each declare TPlatformNetworkState that provide the actual implementation, and the implementation uses clause of NetworkState is appropriately IFDEF’d for each platform so that the actual instance that is created is the one for the specific platform being compiled for.

    I’ve included a demo project below that includes all the necessary files. If you’re going to use TNetworkState in your own project, make sure the files:

    libReachability.a
    NetworkState.pas
    NetworkState.iOS.pas
    NetworkState.Android.pas
    SCNetworkReachability.pas
    CaptiveNetwork.pas

    are either in your project directory or in the compiler search path. Bear in mind that for the Android platform you’ll need to include the Access Network State, and Access Wifi State permissions in the project options:

    For iOS on the device, you’ll need to add the SystemConfiguration framework in the SDK manager. Please refer to this article, and instead of CoreBluetooth (as per the 2nd image), use SystemConfiguration

    Download Here
     

Share This Page