Dismiss Notice



1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$


Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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 N0body, Jan 25, 2014.

  1. N0body

    N0bodyN0body is a Verified Member DelphiFan Administrator 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;

    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:


    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

Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block