用Delphi XE5为Android创建WifiConfiguration [英] Create WifiConfiguration with Delphi XE5 for Android

查看:1087
本文介绍了用Delphi XE5为Android创建WifiConfiguration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建Android上WifiConfiguration。
所有其他属性可设置。
但是,如果我尝试设置SSID或BSSID,我得到一个分段错误(11),以及应用程序和Delphi只是挂起。

  VAR
  WIFIConfig:JWifiConfiguration;
开始
  WIFIConfig:= TJWifiConfiguration.JavaClass.init;
  WIFIConfig.hiddenSSID:= FALSE; - >作品
  WIFIConfig.SSID:= StringtoJString('YOUR_WLAN_SSID'); - >应用程序只是挂
结束;

http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html

  JWifiConfigurationClass =接口(JObjectClass)
    ['{F69F53BC-BC63-436A-8DA9-57389B30CAA8}']
    功能INIT:JWifiConfiguration; CDECL;超载;  结束;  [JavaSignature('机器人/网络/ WIFI / WifiConfiguration')]
  JWifiConfiguration =接口(JObject)
    ['{382E85F2-6BF8-4255-BA3C-03C696BC6451}']
    功能_GetSSID:的jstring;
    程序_SetSSID(价值的jstring);
    功能_GetBSSID:的jstring;
    程序_SetBSSID(价值的jstring);
    功能_GethiddenSSID:布尔;
    程序_SethiddenSSID(价值:布尔);
    功能_GetallowedAuthAlgorithms:JBitSet;
    程序_SetallowedAuthAlgorithms(价值:JBitSet);
    功能_GetallowedGroupCiphers:JBitSet;
    程序_SetallowedGroupCiphers(价值:JBitSet);
    功能_GetallowedKeyManagement:JBitSet;
    程序_SetallowedKeyManagement(价值:JBitSet);
    功能_GetallowedPairwiseCiphers:JBitSet;
    程序_SetallowedPairwiseCiphers(价值:JBitSet);
    功能_GetallowedProtocols:JBitSet;
    程序_SetallowedProtocols(价值:JBitSet);
    功能_GetnetworkId:整数;
    程序_SetnetworkId(价值:整数);
    功能_Get preSharedKey:的jstring;
    程序_Set $​​ P $ pSharedKey(价值的jstring);
    功能_Getstatus:整数;
    程序_Setstatus(价值:整数);
    功能_GetwepTxKeyIndex:整数;
    程序_SetwepTxKeyIndex(价值:整数);
    功能_GetwepKeys:TJavaObjectArray<的jstring取代;
    程序_SetwepKeys(价值:TJavaObjectArray<&的jstring GT;);    物业SSID:读的jstring写_GetSSID _SetSSID;
    物业BSSID:读的jstring写_GetBSSID _SetBSSID;
    物业allowedAuthAlgorithms:JBitSet读_GetallowedAuthAlgorithms写_SetallowedAuthAlgorithms;
    物业allowedGroupCiphers:JBitSet读_GetallowedGroupCiphers写_SetallowedGroupCiphers;
    物业allowedKeyManagement:JBitSet读_GetallowedKeyManagement写_SetallowedKeyManagement;
    物业allowedPairwiseCiphers:JBitSet读_GetallowedPairwiseCiphers写_SetallowedPairwiseCiphers;
    物业allowedProtocols:JBitSet读_GetallowedProtocols写_SetallowedProtocols;
    物业hiddenSSID:布尔读_GethiddenSSID写_SethiddenSSID;
    物业NETWORKID:整数读_GetnetworkId写_SetnetworkId;
    物业preSharedKey:阅读的jstring _Get preSharedKey写_Set $​​ P $ pSharedKey;
    财产优先级:整数读_GetnetworkId写_SetnetworkId;
    财产状况:整数读_Getstatus写_Setstatus;
    物业wepKeys:TJavaObjectArray<&的jstring GT;读_GetwepKeys写_SetwepKeys;
    物业wepTxKeyIndex:整数读_GetwepTxKeyIndex写_SetwepTxKeyIndex;  结束;  TJWifiConfiguration =类(TJavaGenericImport< JWifiConfigurationClass,
    JWifiConfiguration>)
  结束;


解决方案

您错过了 CDECL 调用约定在所有的的JWifiConfiguration 方法。

  [JavaSignature('机器人/网络/ WIFI / WifiConfiguration')]
JWifiConfiguration =接口(JObject)
  ['{382E85F2-6BF8-4255-BA3C-03C696BC6451}']
  功能_GetSSID:的jstring; CDECL;
  程序_SetSSID(价值的jstring); CDECL;
  功能_GetBSSID:的jstring; CDECL;
  程序_SetBSSID(价值的jstring); CDECL;
  功能_GethiddenSSID:布尔; CDECL;
  程序_SethiddenSSID(价值:布尔); CDECL;
  功能_GetallowedAuthAlgorithms:JBitSet; CDECL;
  程序_SetallowedAuthAlgorithms(价值:JBitSet); CDECL;
  功能_GetallowedGroupCiphers:JBitSet; CDECL;
  程序_SetallowedGroupCiphers(价值:JBitSet); CDECL;
  功能_GetallowedKeyManagement:JBitSet; CDECL;
  程序_SetallowedKeyManagement(价值:JBitSet); CDECL;
  功能_GetallowedPairwiseCiphers:JBitSet; CDECL;
  程序_SetallowedPairwiseCiphers(价值:JBitSet); CDECL;
  功能_GetallowedProtocols:JBitSet; CDECL;
  程序_SetallowedProtocols(价值:JBitSet); CDECL;
  功能_GetnetworkId:整数; CDECL;
  程序_SetnetworkId(价值:整数); CDECL;
  功能_Get preSharedKey:的jstring; CDECL;
  程序_Set $​​ P $ pSharedKey(价值的jstring); CDECL;
  功能_Getstatus:整数; CDECL;
  程序_Setstatus(价值:整数); CDECL;
  功能_GetwepTxKeyIndex:整数; CDECL;
  程序_SetwepTxKeyIndex(价值:整数); CDECL;
  功能_GetwepKeys:TJavaObjectArray<的jstring取代; CDECL;
  程序_SetwepKeys(价值:TJavaObjectArray<&的jstring GT;); CDECL;  物业SSID:读的jstring写_GetSSID _SetSSID;
  物业BSSID:读的jstring写_GetBSSID _SetBSSID;
  物业allowedAuthAlgorithms:JBitSet读_GetallowedAuthAlgorithms写_SetallowedAuthAlgorithms;
  物业allowedGroupCiphers:JBitSet读_GetallowedGroupCiphers写_SetallowedGroupCiphers;
  物业allowedKeyManagement:JBitSet读_GetallowedKeyManagement写_SetallowedKeyManagement;
  物业allowedPairwiseCiphers:JBitSet读_GetallowedPairwiseCiphers写_SetallowedPairwiseCiphers;
  物业allowedProtocols:JBitSet读_GetallowedProtocols写_SetallowedProtocols;
  物业hiddenSSID:布尔读_GethiddenSSID写_SethiddenSSID;
  物业NETWORKID:整数读_GetnetworkId写_SetnetworkId;
  物业preSharedKey:阅读的jstring _Get preSharedKey写_Set $​​ P $ pSharedKey;
  财产优先级:整数读_GetnetworkId写_SetnetworkId;
  财产状况:整数读_Getstatus写_Setstatus;
  物业wepKeys:TJavaObjectArray<&的jstring GT;读_GetwepKeys写_SetwepKeys;
  物业wepTxKeyIndex:整数读_GetwepTxKeyIndex写_SetwepTxKeyIndex;
结束;

I'm trying to create a WifiConfiguration for Android. All other properties can be set. But if i try to set the SSID or BSSID, i'm getting a segmentation fault (11) and the app and Delphi just hangs.

var
  WIFIConfig: JWifiConfiguration;
begin
  WIFIConfig :=  TJWifiConfiguration.JavaClass.init; 
  WIFIConfig.hiddenSSID := false;                         -> works
  WIFIConfig.SSID := StringtoJString('"YOUR_WLAN_SSID"'); -> App just hangs
end;

http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html

   JWifiConfigurationClass = interface(JObjectClass)
    ['{F69F53BC-BC63-436A-8DA9-57389B30CAA8}']
    function init: JWifiConfiguration; cdecl; overload;

  end;

  [JavaSignature('android/net/wifi/WifiConfiguration')]
  JWifiConfiguration = interface(JObject)
    ['{382E85F2-6BF8-4255-BA3C-03C696BC6451}']
    function _GetSSID: JString;
    procedure _SetSSID(Value: JString);
    function _GetBSSID: JString;
    procedure _SetBSSID(Value: JString);
    function _GethiddenSSID: boolean;
    procedure _SethiddenSSID(Value: boolean);
    function _GetallowedAuthAlgorithms: JBitSet;
    procedure _SetallowedAuthAlgorithms(Value: JBitSet);
    function _GetallowedGroupCiphers: JBitSet;
    procedure _SetallowedGroupCiphers(Value: JBitSet);
    function _GetallowedKeyManagement: JBitSet;
    procedure _SetallowedKeyManagement(Value: JBitSet);
    function _GetallowedPairwiseCiphers: JBitSet;
    procedure _SetallowedPairwiseCiphers(Value: JBitSet);
    function _GetallowedProtocols: JBitSet;
    procedure _SetallowedProtocols(Value: JBitSet);
    function _GetnetworkId: integer;
    procedure _SetnetworkId(Value: integer);
    function _GetpreSharedKey: JString;
    procedure _SetpreSharedKey(Value: JString);
    function _Getstatus: integer;
    procedure _Setstatus(Value: integer);
    function _GetwepTxKeyIndex: integer;
    procedure _SetwepTxKeyIndex(Value: integer);
    function _GetwepKeys: TJavaObjectArray<JString>;
    procedure _SetwepKeys(Value: TJavaObjectArray<JString>);

    property SSID: JString read _GetSSID write _SetSSID;
    property BSSID: JString read _GetBSSID write _SetBSSID;
    property allowedAuthAlgorithms: JBitSet read _GetallowedAuthAlgorithms write _SetallowedAuthAlgorithms;
    property allowedGroupCiphers: JBitSet read _GetallowedGroupCiphers write _SetallowedGroupCiphers;
    property allowedKeyManagement: JBitSet read _GetallowedKeyManagement write _SetallowedKeyManagement;
    property allowedPairwiseCiphers: JBitSet read _GetallowedPairwiseCiphers write _SetallowedPairwiseCiphers;
    property allowedProtocols: JBitSet read _GetallowedProtocols write _SetallowedProtocols;
    property hiddenSSID: boolean read _GethiddenSSID write _SethiddenSSID;
    property networkId: integer read _GetnetworkId write _SetnetworkId;
    property preSharedKey: JString read _GetpreSharedKey write _SetpreSharedKey;
    property priority: integer read _GetnetworkId write _SetnetworkId;
    property status: integer read _Getstatus write _Setstatus;
    property wepKeys: TJavaObjectArray<JString> read _GetwepKeys write _SetwepKeys;
    property wepTxKeyIndex: integer read _GetwepTxKeyIndex write _SetwepTxKeyIndex;

  end;

  TJWifiConfiguration = class(TJavaGenericImport<JWifiConfigurationClass,
    JWifiConfiguration>)
  end;

解决方案

You're missing the cdecl calling convention on all of your JWifiConfiguration methods.

[JavaSignature('android/net/wifi/WifiConfiguration')]
JWifiConfiguration = interface(JObject)
  ['{382E85F2-6BF8-4255-BA3C-03C696BC6451}']
  function _GetSSID: JString; cdecl;
  procedure _SetSSID(Value: JString); cdecl;
  function _GetBSSID: JString; cdecl;
  procedure _SetBSSID(Value: JString); cdecl;
  function _GethiddenSSID: boolean; cdecl;
  procedure _SethiddenSSID(Value: boolean); cdecl;
  function _GetallowedAuthAlgorithms: JBitSet; cdecl;
  procedure _SetallowedAuthAlgorithms(Value: JBitSet); cdecl;
  function _GetallowedGroupCiphers: JBitSet; cdecl;
  procedure _SetallowedGroupCiphers(Value: JBitSet); cdecl;
  function _GetallowedKeyManagement: JBitSet; cdecl;
  procedure _SetallowedKeyManagement(Value: JBitSet); cdecl;
  function _GetallowedPairwiseCiphers: JBitSet; cdecl;
  procedure _SetallowedPairwiseCiphers(Value: JBitSet); cdecl;
  function _GetallowedProtocols: JBitSet; cdecl;
  procedure _SetallowedProtocols(Value: JBitSet); cdecl;
  function _GetnetworkId: integer; cdecl;
  procedure _SetnetworkId(Value: integer); cdecl;
  function _GetpreSharedKey: JString; cdecl;
  procedure _SetpreSharedKey(Value: JString); cdecl;
  function _Getstatus: integer; cdecl;
  procedure _Setstatus(Value: integer); cdecl;
  function _GetwepTxKeyIndex: integer; cdecl;
  procedure _SetwepTxKeyIndex(Value: integer); cdecl;
  function _GetwepKeys: TJavaObjectArray<JString>; cdecl;
  procedure _SetwepKeys(Value: TJavaObjectArray<JString>); cdecl;

  property SSID: JString read _GetSSID write _SetSSID;
  property BSSID: JString read _GetBSSID write _SetBSSID;
  property allowedAuthAlgorithms: JBitSet read _GetallowedAuthAlgorithms write _SetallowedAuthAlgorithms;
  property allowedGroupCiphers: JBitSet read _GetallowedGroupCiphers write _SetallowedGroupCiphers;
  property allowedKeyManagement: JBitSet read _GetallowedKeyManagement write _SetallowedKeyManagement;
  property allowedPairwiseCiphers: JBitSet read _GetallowedPairwiseCiphers write _SetallowedPairwiseCiphers;
  property allowedProtocols: JBitSet read _GetallowedProtocols write _SetallowedProtocols;
  property hiddenSSID: boolean read _GethiddenSSID write _SethiddenSSID;
  property networkId: integer read _GetnetworkId write _SetnetworkId;
  property preSharedKey: JString read _GetpreSharedKey write _SetpreSharedKey;
  property priority: integer read _GetnetworkId write _SetnetworkId;
  property status: integer read _Getstatus write _Setstatus;
  property wepKeys: TJavaObjectArray<JString> read _GetwepKeys write _SetwepKeys;
  property wepTxKeyIndex: integer read _GetwepTxKeyIndex write _SetwepTxKeyIndex;
end;

这篇关于用Delphi XE5为Android创建WifiConfiguration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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