wifimanager と wifiinfo (android) を変換しようとしましたが、なぜセグメンテーション違反が発生したのかわかりません。私のコード:
http://developer.android.com/reference/android/net/wifi/WifiInfo.html http://developer.android.com/reference/android/net/wifi/WifiManager.html
unit wifi1;
interface
uses
System.SysUtils,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes,
FMX.Helpers.Android;
//-------------------------------- wifi manager ---------------------------------------//
type
JWifiManager = interface;
JWifiInfo = interface;
JWifiManagerClass = interface(JObjectClass)
['{69F35EA7-3EB9-48AA-B7FC-4FFD0E7D712F}']
function _GetACTION_PICK_WIFI_NETWORK: JString;
function _GetEXTRA_WIFI_INFO: JString;
function _GetWIFI_STATE_CHANGED_ACTION: JString;
property ACTION_PICK_WIFI_NETWORK: JString read _GetACTION_PICK_WIFI_NETWORK;
property EXTRA_WIFI_INFO: JString read _GetEXTRA_WIFI_INFO;
property WIFI_STATE_CHANGED_ACTION: JString read _GetWIFI_STATE_CHANGED_ACTION;
end;
[JavaSignature('android.net.wifi.WifiManager')]
JWifiManager = interface(JObject)
['{DA7107B9-1FAD-4A9E-AA09-8D5B84614E60}']
function isWifiEnabled:Boolean;cdecl;
function setWifiEnabled(enabled:Boolean):Boolean; cdecl;
//function getConfiguredNetworks : JList;cdecl;
function getConnectionInfo :JWifiInfo; cdecl;
end;
TJWifiManager = class(TJavaGenericImport<JWifiManagerClass, JWifiManager>) end;
//-------------------------------- wifi info ---------------------------------------//
JWifiInfoClass = interface(JObjectClass)
['{2B1CE79F-DE4A-40D9-BB2E-7F9F118D8C08}']
function _GetLINK_SPEED_UNITS:JString;
property LINK_SPEED_UNITS: JString read _GetLINK_SPEED_UNITS;
end;
[JavaSignature('android.net.wifi.WifiInfo')]
JWifiInfo = interface(JObject)
['{4F09E865-DB04-4E64-8C81-AEFB36DABC45}']
function getBSSID:jString; cdecl;
function getHiddenSSID:Boolean; cdecl;
function getIpAddress:integer; cdecl;
function getLinkSpeed:integer; cdecl;
function getMacAddress:JString; cdecl;
function getNetworkId:integer; cdecl;
function getRssi:integer; cdecl;
function GetSSID:jString; cdecl;
end;
TJWifiInfo= class(TJavaGenericImport<JWifiInfoClass, JWifiInfo>)
end;
implementation
end.
//-----------------------------------------------------------------------
私のテストは次のとおりです。
var obj:jobject;
wm:jwifimanager;
Winfo:jwifiinfo;
ip:integer;
mac:string;
jmac:JString;
begin
obj:=SharedActivity.getSystemService(TJActivity.JavaClass.WIFI_SERVICE);
wm:= Tjwifimanager.Wrap((obj as ILocalObject).GetObjectID);
Winfo:=TJWifiInfo.Create;
winfo:=wm.getconnectioninfo; <- segmentation fault
ip:=winfo.getIpAddress;
jmac:=winfo.getMacAddress;
mac:=JStringToString(jmac);
end;
これの何が問題なのですか?( wifimanager のメソッドは機能しますが、 getconnectioninfo は機能しません)
元のJava 投稿: Android で wifi IP アドレスを検出しますか?
この関数を呼び出すときのLOGCAT:
そして、これはデルファイのプロジェクトです: PROJECT DELPHI