0

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

Sam
  • 2,473
  • 3
  • 18
  • 29

1 Answers1

0

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);
Dave Nottage
  • 3,411
  • 1
  • 20
  • 57
  • 1
    `FNetworkActiveListener` should be declared as `JConnectivityManager_OnNetworkActiveListener` instead, since that is what `addDefaultNetworkActiveListener()` is expecting. And just like in Win32, you shouldn't mix object references and interface references (even if the reference counting issue is not a problem in mobile). – Remy Lebeau Aug 21 '17 at 22:26
  • @RemyLebeau Not saying that it isn't a problem, however you might like to report that as such for all the instances that EMBT do the same in the RTL/FMX units – Dave Nottage Aug 22 '17 at 01:11