Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!

To get the NetworkInfo using the ConnectivityManager of Android

Author: h.mohri


Using ConnectivityManager with C++Builder

With C++Builder 10.2 Tokyo Android ConnectivityManager class is available.
Use the ConnectivityManager, you can get NetworkInfo
NetworkInfo see various network information.
inside that, The getType() function is Reports the type of network.
The getType() function return is int.

int type
0x00000000 TYPE_MOBILE
0x00000001 TYPE_WIFI
0x00000006 TYPE_WIMAX
0x00000009 TYPE_ETHERNET

I tried ways to get NetworkInfo.

Declare _di_JConnectivityManager variable.

_di_JConnectivityManager is the ConnectivityManager class interface.

 _di_JConnectivityManager    f_ConnectivityManager;

It creates to use ‘_di_JConnectivityManager’.

template <typename T1, typename T2> void __fastcall Tfm_main_wifistatus::getService(_di_JObject obj, T1& iobj)
    if (obj != nullptr)
        iobj = T2::Wrap(_di_ILocalObject(obj)->GetObjectID());
void __fastcall Tfm_main_wifistatus::FormCreate(TObject *Sender)
    //Form creation.Using TAndroidHelper, get the CONNECTIVITY_SERVICE.
    getService<_di_JConnectivityManager, TJConnectivityManager>(
        TAndroidHelper::Context->getSystemService(TJContext::JavaClass->CONNECTIVITY_SERVICE), f_ConnectivityManager);

Get the _di_JNetworkInfo using the getActiveNetworkInfo() function.

#define TYPE_WIFI 0x00000001
#define TYPE_MOBILE 0x00000000
#define TYPE_VPN 0x00000011
#define TYPE_WIMAX 0x00000006

void __fastcall Tfm_main_wifistatus::Timer1Timer(TObject *Sender)
        UnicodeString net_str;
        _di_JNetworkInfo n_info = f_ConnectivityManager->getActiveNetworkInfo();
        if (n_info != nullptr)
            switch (n_info->getType())
            case TYPE_WIFI:
                net_str = L"(TYPE_WIFI)";    break;
            case TYPE_MOBILE:
                net_str = L"(TYPE_MOBILE)";  break;
            case TYPE_VPN:
                net_str = L"(TYPE_VPN)"; break;
            net_str = L"(nullptr)";

You can get the status of a network interface.

What's New for RAD Studio 11

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts
C++CodeIDERAD Studio

C++Builder Compilers available in Version 11 Alexandria

C++CodeIDERAD Studio

5 Great Modern C++ Posts To Add To Your Toolkit


ZXing.Delphi (Zebra Crossing) Tested with RAD 11 for Android and iOS


How To Migrate Legacy C++ Apps To Unicode

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.