android wifi问题 各位大仙 大牛 帮帮忙啊!!

xinke87 2011-06-26 05:44:56
现在我的程序可以通过wifi搜索到很多热点,包括自家的路由器,家里的路由器已经加密了。我肯定知道密码。
现在的问题是,我如何通过编程能够实现这样一个功能:

1.判断家里的路由器是不是加密了
2.如果加密了当点击进行连接的时候就跳出一个对话框输入密码然后进行连接。

各位大仙 大牛 这个问题困扰好久了,一直没有找到解决问题的办法。谁能指点指点??
...全文
185 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fontlose 2011-06-26
  • 打赏
  • 举报
回复
Quote=引用 3 楼 xinke87 的回复:]
1.判断家里的路由器是不是加密了????
[/Quote]


public class WifiManager

boolean startScan()
Request a scan for access points.

List<ScanResult> getScanResults()
Return the results of the latest access point scan.


public class ScanResult

Fields
public String BSSID The address of the access point.
public String SSID The network name.
public String capabilities Describes the authentication, key management, and encryption schemes supported by the access point.
public int frequency The frequency in MHz of the channel over which the client is communicating with the access point.
public int level The detected signal level in dBm.







xinke87 2011-06-26
  • 打赏
  • 举报
回复
1.判断家里的路由器是不是加密了????
fontlose 2011-06-26
  • 打赏
  • 举报
回复
WifiManager 已经提供了搜索无线路由获取网络配置等接口的了
你懒得设置可以直接调用系统的wifi设置activity

Intent it = new Intent();
it.setAction(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
// android.provider.Settings.ACTION_WIFI_SETTINGS
// android.provider.Settings.ACTION_WIFI_IP_SETTINGS
this.startActivityForResult(it,0);
fontlose 2011-06-26
  • 打赏
  • 举报
回复
参考下WifiManager 和 WifiConfiguration 两个类


WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"SSIDName\"";
wc.preSharedKey = "\"password\"";
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean b = wifi.enableNetwork(res, true);
Log.d("WifiPreference", "enableNetwork returned " + b );

80,356

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧