My project developing by Delphi XE7 for Androiod device need the function declared in the title.
I found a piece of code which can run and get the correct results on Windows and IOS platform. But on an Android device, the results are always: IP address = 127.0.0.1, subnet mask is blank.
procedure TForm1.RefreshList;
var
LList: TIdStackLocalAddressList;
I: Integer;
AAddresses: TStrings;
begin
AAddresses := TStringList.Create;
try
TIdStack.IncUsage;
try
LList := TIdStackLocalAddressList.Create;
try
// for backwards compatibility, return only IPv4 addresses
GStack.GetLocalAddressList(LList);
if LList.Count > 0 then begin
AAddresses.BeginUpdate;
try
for I := 0 to LList.Count-1 do begin
if LList[I].IPVersion = Id_IPv4 then begin
AAddresses.Add(
LList[I].IPAddress+':'+
TIdStackLocalAddressIPv4(LList[I]).SubNetMask);
end;
end;
finally
AAddresses.EndUpdate;
end;
end;
finally
LList.Free;
end;
finally
TIdStack.DecUsage;
end;
if AAddresses.Count > 0 then
Text1.Text:= AAddresses.Text;
finally
AAddresses.Free;
end;
end;
I found that by android.net.wifi.WifiManager.getDhcpInfo
can probably get the information, but I do not know how to use the interface in Delphi or is that the right way?