UnitAndroidapi.JNI.Network;InterfacefunctionIsconnected:boolean;functionIswificonnected:boolean;functionIsmobileconnected:boolean;Implementationusessystem.sysutils, Androidapi.jnibridge, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.JavaTypes, FMX. helpers.android;typeJconnectivitymanager=Interface; Jnetworkinfo=Interface; Jnetworkinfoclass=Interface(jobjectclass) ['{e92e86e8-0bde-4d5f-b44e-3148bd63a14c}'] End; [Javasignature ('Android/net/networkinfo')] Jnetworkinfo=Interface(jobject) ['{6df61a40-8d17-4e51-8ef2-32cdc81ac372}'] {Methods} functionIsavailable:boolean;cdecl; functionIsconnected:boolean;cdecl; functionIsconnectedorconnecting:boolean;cdecl; End; Tjnetworkinfo=class(Tjavagenericimport)End; Jconnectivitymanagerclass=Interface(jobjectclass) ['{E03A261F-59A4-4236-8CDF-0068FC6C5FA1}'] {Property Methods} function_gettype_wifi:integer;cdecl; function_gettype_wimax:integer;cdecl; function_gettype_mobile:integer;cdecl; {Properties} PropertyType_wifi:integerRead_gettype_wifi; PropertyType_wimax:integerRead_gettype_wimax; PropertyType_mobile:integerRead_gettype_mobile; End; [Javasignature ('Android/net/connectivitymanager')] Jconnectivitymanager=Interface(jobject) ['{1c4c1873-65ae-4722-8eef-36bbf423c9c5}'] {Methods} functionGetactivenetworkinfo:jnetworkinfo;cdecl; functionGetnetworkinfo (Networktype:integer): Jnetworkinfo;cdecl; End; Tjconnectivitymanager=class(Tjavagenericimport)End;functionGetconnectivitymanager:jconnectivitymanager;varConnectivityservicenative:jobject;beginconnectivityservicenative:=Sharedactivitycontext.getsystemservice (TJContext.JavaClass.CONNECTIVITY_SERVICE); if notAssigned (connectivityservicenative) Then RaiseException.create ('Could not locate Connectivity Service'); Result:=Tjconnectivitymanager.wrap ((connectivityservicenative asilocalobject). Getobjectid); if notAssigned (Result) Then RaiseException.create ('Could not access Connectivity Manager');End;functionIsconnected:boolean;varConnectivitymanager:jconnectivitymanager; Activenetwork:jnetworkinfo;beginConnectivitymanager:=Getconnectivitymanager; Activenetwork:=Connectivitymanager.getactivenetworkinfo; Result:= Assigned (activenetwork) andactivenetwork.isconnected;End;functionIswificonnected:boolean;varConnectivitymanager:jconnectivitymanager; Wifinetwork:jnetworkinfo;beginConnectivitymanager:=Getconnectivitymanager; Wifinetwork:=Connectivitymanager.getnetworkinfo (TJConnectivityManager.JavaClass.TYPE_WIFI); Result:=wifinetwork.isconnected;End;functionIsmobileconnected:boolean;varConnectivitymanager:jconnectivitymanager; Mobilenetwork:jnetworkinfo;beginConnectivitymanager:=Getconnectivitymanager; Mobilenetwork:=Connectivitymanager.getnetworkinfo (TJConnectivityManager.JavaClass.TYPE_MOBILE); Result:=mobilenetwork.isconnected;End;End.
Call Method:
ifIsConnected ThenShowMessage ('isconnected');ifiswificonnected ThenShowMessage ('iswificonnected');ifismobileconnected ThenShowMessage ('ismobileconnected');