Using the solution mentioned here, I was able to get the status of network. But I also need to implement the event for when the status changes. I know I have to use the addDefaultNetworkActiveListener procedure, but I am having trouble with the interface of OnNetworkActiveListener
. Does anyone know what the interface for OnNetworkActiveListener
looks like?
Thank you Sam
You'd need to construct something like this:
uses
Androidapi.JNIBridge, Androidapi.JNI.Net;
type
TNetworkActiveListener = class(TJavaLocal, JConnectivityManager_OnNetworkActiveListener)
public
procedure onNetworkActive; cdecl;
end;
Then declare a variable:
FNetworkActiveListener: TNetworkActiveListener;
create it and add it:
FNetworkActiveListener := TNetworkActiveListener.Create;
// Use the code from the other answer for GetConnectivityManager
GetConnectivityManager.addDefaultNetworkActiveListener(FNetworkActiveListener);