android创建wifi热点,Android 4.0.3创建wifi热点API

你好,我试图从我的应用程序创建一个接入点。我可以站在AP上,但不能使用我设置的配置。我使用的是HTC感觉XEAndroid 4.0.3创建wifi热点API

WifiManager wifiManager = (WifiManager) rc.getSystemService(Context.WIFI_SERVICE);

if(wifiManager.isWifiEnabled())

{

wifiManager.setWifiEnabled(false);

}

Method[] wmMethods = wifiManager.getClass().getDeclaredMethods();

boolean methodFound=false;

WifiConfiguration netConfig = new WifiConfiguration();

netConfig.SSID = "MyWifiAP";

netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);

netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);

netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

for(Method method: wmMethods){

if(method.getName().equals("setWifiApEnabled")){

methodFound=true;

try {

boolean apstatus=(Boolean) method.invoke(wifiManager, netConfig,true);

for (Method isWifiApEnabledmethod: wmMethods){

if(isWifiApEnabledmethod.getName().equals("isWifiApEnabled")){

while(!(Boolean)isWifiApEnabledmethod.invoke(wifiManager)){

};

for(Method method1: wmMethods){

if(method1.getName().equals("getWifiApState")){

int apstate;

apstate=(Integer)method1.invoke(wifiManager);

for(Method method2: wmMethods){

if(method2.getName().equals("getWifiApConfiguration")){

try {

netConfig=(WifiConfiguration)method2.invoke(wifiManager);

} catch (IllegalArgumentException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IllegalAccessException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (InvocationTargetException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Log.e("CLIENT", "\nSSID:"+netConfig.SSID+"\nPassword:"+netConfig.preSharedKey+"\n");

if (apstate==0) {

Log.d("basura", "apstate es: "+apstate);

}

}

}

}

}

} catch (IllegalArgumentException e) {

e.printStackTrace();

} catch (IllegalAccessException e) {

e.printStackTrace();

} catch (InvocationTargetException e) {

e.printStackTrace();

}

}

}

当我打印:

Log.e( “客户”, “\ nSSID:” + netConfig.SSID + “\ n密码:” + netConfig.preSharedKey +“\ N“);

我得到:

nSSID:空 n密码:空

2012-08-23

asfarto

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值