Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Delphi XE5 - JWiFiManager Interface Needed



Permlink Replies: 8 - Last Post: Jun 19, 2014 8:59 AM Last Post By: Kaspar Neuensch...
Martin Searancke

Posts: 53
Registered: 11/22/02
Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2013 8:25 PM
I am trying to find an interface to what I assume should be called JWiFiManager for Android development in XE5.

I am trying to access this class:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#createMulticastLock%28java.lang.String%29
So that I can receive multicast UDP packets in my Android app.

This is the class that is returned by:
SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE)

I cannot find this or anything like it in the interfaced distributed with Delphi.

Thanks in advance,
Martin

--
Martin Searancke
Dream Solutions
http://www.lightfactory.net
Chee Wee Chua

Posts: 108
Registered: 9/8/06
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 26, 2013 10:00 PM   in response to: Martin Searancke in response to: Martin Searancke
On Thu, 26 Sep 2013 20:25:19 -0700, Martin Searancke <> wrote:

I am trying to find an interface to what I assume should be called JWiFiManager for Android development in XE5.

I am trying to access this class:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#createMulticastLock%28java.lang.String%29
So that I can receive multicast UDP packets in my Android app.

This is the class that is returned by:
SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE)

Can you contact me at chuacw at gmail dot com please?
pete henry

Posts: 4
Registered: 3/14/00
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 27, 2013 3:48 AM   in response to: Martin Searancke in response to: Martin Searancke
Martin Searancke wrote:
I am trying to find an interface to what I assume should be called JWiFiManager for Android development in XE5.

I am trying to access this class:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#createMulticastLock%28java.lang.String%29

The class Wifimanager is listed below - if you can't find it in the stuff that is delivered by XE5 you might have to import it yourself using JNI
There is a complete bluff your way guide at http://www.pclviewer.com/android

Pete

// android/net/wifi/WifiManager
METHOD=<init>()V
METHOD=addNetwork(Landroid/net/wifi/WifiConfiguration;)I
METHOD=calculateSignalLevel(II)I
METHOD=compareSignalLevel(II)I
METHOD=createMulticastLock(Ljava/lang/String;)Landroid/net/wifi/WifiManager$MulticastLock;
METHOD=createWifiLock(ILjava/lang/String;)Landroid/net/wifi/WifiManager$WifiLock;
METHOD=createWifiLock(Ljava/lang/String;)Landroid/net/wifi/WifiManager$WifiLock;
METHOD=disableNetwork(I)Z
METHOD=disconnect()Z
METHOD=enableNetwork(IZ)Z
METHOD=getConfiguredNetworks()Ljava/util/List;
METHOD=getConnectionInfo()Landroid/net/wifi/WifiInfo;
METHOD=getDhcpInfo()Landroid/net/DhcpInfo;
METHOD=getScanResults()Ljava/util/List;
METHOD=getWifiState()I
METHOD=isWifiEnabled()Z
METHOD=pingSupplicant()Z
METHOD=reassociate()Z
METHOD=reconnect()Z
METHOD=removeNetwork(I)Z
METHOD=saveConfiguration()Z
METHOD=setWifiEnabled(Z)Z
METHOD=startScan()Z
METHOD=updateNetwork(Landroid/net/wifi/WifiConfiguration;)I
FIELD=ACTION_PICK_WIFI_NETWORK
FIELD=ERROR_AUTHENTICATING
FIELD=EXTRA_BSSID
FIELD=EXTRA_NETWORK_INFO
FIELD=EXTRA_NEW_RSSI
FIELD=EXTRA_NEW_STATE
FIELD=EXTRA_PREVIOUS_WIFI_STATE
FIELD=EXTRA_SUPPLICANT_CONNECTED
FIELD=EXTRA_SUPPLICANT_ERROR
FIELD=EXTRA_WIFI_INFO
FIELD=EXTRA_WIFI_STATE
FIELD=NETWORK_IDS_CHANGED_ACTION
FIELD=NETWORK_STATE_CHANGED_ACTION
FIELD=RSSI_CHANGED_ACTION
FIELD=SCAN_RESULTS_AVAILABLE_ACTION
FIELD=SUPPLICANT_CONNECTION_CHANGE_ACTION
FIELD=SUPPLICANT_STATE_CHANGED_ACTION
FIELD=WIFI_MODE_FULL
FIELD=WIFI_MODE_FULL_HIGH_PERF
FIELD=WIFI_MODE_SCAN_ONLY
FIELD=WIFI_STATE_CHANGED_ACTION
FIELD=WIFI_STATE_DISABLED
FIELD=WIFI_STATE_DISABLING
FIELD=WIFI_STATE_ENABLED
FIELD=WIFI_STATE_ENABLING
FIELD=WIFI_STATE_UNKNOWN

Martin Searancke

Posts: 53
Registered: 11/22/02
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 28, 2013 7:46 PM   in response to: pete henry in response to: pete henry
Thank you, that has got me on the path to a solution. I have implemented the following but am getting a segmentation fault when I try to create an instance of the WiFiManager class using getSystemService. There must be something I am missing. I feel I am close.

This is how I am trying to create the class...
  wifi_manager := TJWiFiManager.JavaClass.getSystemService(TJContext.JavaClass.WIFI_SERVICE);


And here is my implementation unit...
Type
  JWiFiManager = interface;   // android/net/wifi/WifiManager
  JMulticastLock = interface; // android/net/wifi/WifiManager$MulticastLock
 
  JWiFiManagerClass = interface(JObjectClass)
   ['{F69F53AE-BC63-436A-8F69-57389B30CAA8}']
    function getSystemService(Contex: JString): JWiFiManager; cdecl;
  end;
 
  [JavaSignature('android/net/wifi/WifiManager')]
  JWiFiManager = interface(JObject)
  ['{382E85F2-6BF8-4255-BA3C-03C696AA6450}']
    function createMulticastLock(tag: JString): JMulticastLock;
  end;
 
  TJWiFiManager = class(TJavaGenericImport<JWiFiManagerClass, JWiFiManager>) end;
 
  JMulticastLockClass = interface(JObjectClass)
  ['{C0546633-3DF2-46B0-8E2C-C14411674A6F}']
  end;
 
  [JavaSignature('android/net/wifi/WifiManager$MulticastLock')]
  JMulticastLock = interface(JObject)
  ['{CFA00D0C-097C-45E3-8B33-0E5A6C9FB9F1}']
    procedure acquire();
    function isHeld(): Boolean;
    procedure reslease();
    procedure setReferenceCounted(refCounted: boolean);
  end;
 
  TJMulticastLock = class(TJavaGenericImport<JMulticastLockClass, JMulticastLock>) end;


pete henry wrote:
Martin Searancke wrote:
I am trying to find an interface to what I assume should be called JWiFiManager for Android development in XE5.

I am trying to access this class:
http://developer.android.com/reference/android/net/wifi/WifiManager.html#createMulticastLock%28java.lang.String%29

The class Wifimanager is listed below - if you can't find it in the stuff that is delivered by XE5 you might have to import it yourself using JNI
There is a complete bluff your way guide at http://www.pclviewer.com/android

Pete

// android/net/wifi/WifiManager
METHOD=<init>()V
METHOD=addNetwork(Landroid/net/wifi/WifiConfiguration;)I
METHOD=calculateSignalLevel(II)I
METHOD=compareSignalLevel(II)I
METHOD=createMulticastLock(Ljava/lang/String;)Landroid/net/wifi/WifiManager$MulticastLock;
METHOD=createWifiLock(ILjava/lang/String;)Landroid/net/wifi/WifiManager$WifiLock;
METHOD=createWifiLock(Ljava/lang/String;)Landroid/net/wifi/WifiManager$WifiLock;
METHOD=disableNetwork(I)Z
METHOD=disconnect()Z
METHOD=enableNetwork(IZ)Z
METHOD=getConfiguredNetworks()Ljava/util/List;
METHOD=getConnectionInfo()Landroid/net/wifi/WifiInfo;
METHOD=getDhcpInfo()Landroid/net/DhcpInfo;
METHOD=getScanResults()Ljava/util/List;
METHOD=getWifiState()I
METHOD=isWifiEnabled()Z
METHOD=pingSupplicant()Z
METHOD=reassociate()Z
METHOD=reconnect()Z
METHOD=removeNetwork(I)Z
METHOD=saveConfiguration()Z
METHOD=setWifiEnabled(Z)Z
METHOD=startScan()Z
METHOD=updateNetwork(Landroid/net/wifi/WifiConfiguration;)I
FIELD=ACTION_PICK_WIFI_NETWORK
FIELD=ERROR_AUTHENTICATING
FIELD=EXTRA_BSSID
FIELD=EXTRA_NETWORK_INFO
FIELD=EXTRA_NEW_RSSI
FIELD=EXTRA_NEW_STATE
FIELD=EXTRA_PREVIOUS_WIFI_STATE
FIELD=EXTRA_SUPPLICANT_CONNECTED
FIELD=EXTRA_SUPPLICANT_ERROR
FIELD=EXTRA_WIFI_INFO
FIELD=EXTRA_WIFI_STATE
FIELD=NETWORK_IDS_CHANGED_ACTION
FIELD=NETWORK_STATE_CHANGED_ACTION
FIELD=RSSI_CHANGED_ACTION
FIELD=SCAN_RESULTS_AVAILABLE_ACTION
FIELD=SUPPLICANT_CONNECTION_CHANGE_ACTION
FIELD=SUPPLICANT_STATE_CHANGED_ACTION
FIELD=WIFI_MODE_FULL
FIELD=WIFI_MODE_FULL_HIGH_PERF
FIELD=WIFI_MODE_SCAN_ONLY
FIELD=WIFI_STATE_CHANGED_ACTION
FIELD=WIFI_STATE_DISABLED
FIELD=WIFI_STATE_DISABLING
FIELD=WIFI_STATE_ENABLED
FIELD=WIFI_STATE_ENABLING
FIELD=WIFI_STATE_UNKNOWN


--
Martin Searancke
Dream Solutions
http://www.lightfactory.net
pete henry

Posts: 4
Registered: 3/14/00
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2013 8:18 AM   in response to: Martin Searancke in response to: Martin Searancke
Martin Searancke wrote:
Thank you, that has got me on the path to a solution. I have implemented the following but am getting a segmentation fault when I try to create an instance of the WiFiManager class using getSystemService. There must be something I am missing. I feel I am close.

It looks "close". Have you added in PROJECT OPTIONS USES PERMISSIONS

ACCESS NETWORK STATE
CHANGE WIFI STATE

to the manifest?
Martin Searancke

Posts: 53
Registered: 11/22/02
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 29, 2013 12:33 PM   in response to: pete henry in response to: pete henry
Yes, both of these are set. I should have included that info in my previous post.

Martin

It looks "close". Have you added in PROJECT OPTIONS USES PERMISSIONS

ACCESS NETWORK STATE
CHANGE WIFI STATE

to the manifest?

--
Martin Searancke
Dream Solutions
http://www.lightfactory.net
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 30, 2013 11:22 AM   in response to: Martin Searancke in response to: Martin Searancke
Martin wrotE:

wifi_manager := TJWiFiManager.JavaClass.getSystemService(TJContext.JavaClass.WIFI_SERVICE);

You need to call getSystemService() on the RTL's global SharedActivityContext
object instead, and then wrap the returned object so you can access its members,
eg:

function GetWiFiManager: JWiFiManager;
var
  Obj: JObject;
begin
  Obj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  if not Assigned(Obj) then
    raise Exception.Create('Could not locate Wifi Service');
  Result := TJWiFiManager.Wrap((Obj as ILocalObject).GetObjectID);
  if not Assigned(Result) then
    raise Exception.Create('Could not access Wifi Manager');
end;
...
wifi_manager := GetWiFiManager;


--
Remy Lebeau (TeamB)
Martin Searancke

Posts: 53
Registered: 11/22/02
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 30, 2013 2:08 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thank you. Here is the complete code for anyone looking for how to receive broadcast UDP packets on Android...

unit Androidapi.JNI.WiFiManager;
 
interface
 
uses
  Androidapi.JNIBridge, Androidapi.Jni,  androidapi.JNI.JavaTypes, androidapi.JNI.Net,
  androidapi.JNI.Os, FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText, SysUtils;
 
Type
  JWiFiManager = interface;   // android/net/wifi/WifiManager
  JMulticastLock = interface; // android/net/wifi/WifiManager$MulticastLock
 
  JWiFiManagerClass = interface(JObjectClass)
   ['{F69F53AE-BC63-436A-8F69-57389B30CAA8}']
    function getSystemService(Contex: JString): JWiFiManager; cdecl;
  end;
 
  [JavaSignature('android/net/wifi/WifiManager')]
  JWiFiManager = interface(JObject)
  ['{382E85F2-6BF8-4255-BA3C-03C696AA6450}']
    function createMulticastLock(tag: JString): JMulticastLock;
  end;
 
  TJWiFiManager = class(TJavaGenericImport<JWiFiManagerClass, JWiFiManager>) end;
 
  JMulticastLockClass = interface(JObjectClass)
  ['{C0546633-3DF2-46B0-8E2C-C14411674A6F}']
  end;
 
  [JavaSignature('android/net/wifi/WifiManager$MulticastLock')]
  JMulticastLock = interface(JObject)
  ['{CFA00D0C-097C-45E3-8B33-0E5A6C9FB9F1}']
    procedure acquire();
    function isHeld(): Boolean;
    procedure release();
    procedure setReferenceCounted(refCounted: boolean);
  end;
 
  TJMulticastLock = class(TJavaGenericImport<JMulticastLockClass, JMulticastLock>) end;
 
  function GetWiFiManager: JWiFiManager;
 
implementation
 
function GetWiFiManager: JWiFiManager;
var
  Obj: JObject;
begin
  Obj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  if not Assigned(Obj) then
    raise Exception.Create('Could not locate Wifi Service');
  Result := TJWiFiManager.Wrap((Obj as ILocalObject).GetObjectID);
  if not Assigned(Result) then
    raise Exception.Create('Could not access Wifi Manager');
end;


And to get the necessary lock...
  wifi_manager := GetWiFiManager;
  multiCastLock := wifi_manager.createMulticastLock(StringToJString('LightFactory Remote'));
  multiCastLock.setReferenceCounted(true);
  multiCastLock.acquire;


Martin

Remy Lebeau (TeamB) wrote:
Martin wrotE:

wifi_manager := TJWiFiManager.JavaClass.getSystemService(TJContext.JavaClass.WIFI_SERVICE);

You need to call getSystemService() on the RTL's global SharedActivityContext
object instead, and then wrap the returned object so you can access its members,
eg:

function GetWiFiManager: JWiFiManager;
var
  Obj: JObject;
begin
  Obj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  if not Assigned(Obj) then
    raise Exception.Create('Could not locate Wifi Service');
  Result := TJWiFiManager.Wrap((Obj as ILocalObject).GetObjectID);
  if not Assigned(Result) then
    raise Exception.Create('Could not access Wifi Manager');
end;
...
wifi_manager := GetWiFiManager;


--
Remy Lebeau (TeamB)

--
Martin Searancke
Dream Solutions
http://www.lightfactory.net
Kaspar Neuensch...

Posts: 2
Registered: 2/24/13
Re: Delphi XE5 - JWiFiManager Interface Needed
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 19, 2014 8:59 AM   in response to: Martin Searancke in response to: Martin Searancke
Hi everyone

I am trying to do the same stuff, but I keep getting a segmentation fault as soon as I "wrap" the pointer which is returned by GetObjectId, to get the Wifi-manager.

I am using a google Nexus 5 mobile phone with Android 4.4.3.

Any ideas?

Thanks in advance

Kaspar
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02