德尔福xe5 Wifimanager和WifiInfo丁文 [英] delphi xe5 Wifimanager and WifiInfo coversion

查看:751
本文介绍了德尔福xe5 Wifimanager和WifiInfo丁文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图隐蔽的wifimanager和wifiinfo(And​​roid)和我不明白为什么我有段错误,我看到wifimanager效果很好,但是当我尝试调用wifiinfo我得到段错误的一些方法。我的code:

i tried to covert the wifimanager and wifiinfo (android) and i don't understand why i had segmentation fault, i saw that wifimanager worked well, but when i try to call some methods of wifiinfo i get "segmentation fault". my code:

http://developer.android.com/reference/android/净/ 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)

what can be wrong with this? (the methods of wifimanager works but not getconnectioninfo )

原始的Java POST:在Android上检测无线IP地址

ORIGINAL JAVA POST: Detect wifi IP address on Android?

logcat的时候调用这个函数:

LOGCAT when i call this function:

这是在Delphi项目:德尔菲项目

and this is the project in delphi: PROJECT DELPHI

推荐答案

什么是主要毛病是缺乏检查零值,这因此导致您的分段错误(至少我期待这是案例 - WM是零,例如)

What is primarily wrong with it is that lack of checking for nil values, which consequently leads to your segmentation fault (at least I'm expecting this to be the case - wm being nil, for example).

您可以尝试参考code片段在<一个href=\"http://stackoverflow.com/questions/18888345/how-to-check-if-network-is-available-on-android-delphi-xe5\">this SO回答作为一般的指导与Android网络类的工作。这应该有助于从目前来看,以代替在code直接指向错误的。尝试code OUT,并确保你了解它是如何运作的。然后,它应该帮助你找出什么是你犯错误的片段。

You can try referring to the code snippet in this SO answer as a general guide to working with the Android network classes. That should help for now, in lieu of a direct pointer to the error in your code. Try that code out and ensure you understand how it operates. It should then help you identify what is errant in your snippet.

与code一个潜在问题是使用点分隔的属性,但Android的RTL类属性,与上述片段中,使用沿着/作为分隔符。

One potential problem with the code is the attributes are using dot-separators, but the RTL Android class attributes, along with the aforementioned snippet, use / as a separator.

明智地使用logcat中(从监控应用程序内说)将帮助确定是否是由该看到的操作系统抛出的日志消息为这个应用程序执行期间的情况。

Judicious use of logcat (say from within the monitor app) would help identify if this was the case by seeing what the OS throws out as log messages for the period this app executes.

哦,本来应该先检查一件事 - 你添加的访问无线状态的权限,您的应用程序?这将导致问题与,呃,访问无线网络状态信息,natch。

Oh, and one thing that should have been checked first - have you added the Access wifi state permission to your app? That will cause issues with, erm, accessing wifi state information, natch.

这篇关于德尔福xe5 Wifimanager和WifiInfo丁文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆