之前查了好多大牛的博客,总结了一下。

把代码分享给大家。

功能:创建热点、获取热点名、检查是否开启wifi热点、关闭热点、开热点手机获取其他连入手机IP地址

想了解wifi开发的,看我的下一篇文章。   http://blog.csdn.net/guang_liang_/article/details/55224757

public class Wifi_APManager {private WifiManager mWifiManager;private Context mContext;public Wifi_APManager(Context context){this.mContext=context;mWifiManager=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);}/*** 创建热点* @param mSSID 热点名称* @param mPasswd 热点密码* @param isOpen 是否是开放热点*/public void startWifiAp(String mSSID,String mPasswd,boolean isOpen){Method method1=null;try {method1=mWifiManager.getClass().getMethod("setWifiApEnabled",WifiConfiguration.class,boolean.class);WifiConfiguration netConfig=new WifiConfiguration();netConfig.SSID=mSSID;netConfig.preSharedKey=mPasswd;netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);if (isOpen) {netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);}else {netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);}netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);method1.invoke(mWifiManager,netConfig,true);} catch (NoSuchMethodException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();}}/**获取热点名**/public String getApSSID() {try {Method localMethod = this.mWifiManager.getClass().getDeclaredMethod("getWifiApConfiguration", new Class[0]);if (localMethod == null) return null;Object localObject1 = localMethod.invoke(this.mWifiManager,new Object[0]);if (localObject1 == null) return null;WifiConfiguration localWifiConfiguration = (WifiConfiguration) localObject1;if (localWifiConfiguration.SSID != null) return localWifiConfiguration.SSID;Field localField1 = WifiConfiguration.class .getDeclaredField("mWifiApProfile");if (localField1 == null) return null;localField1.setAccessible(true);Object localObject2 = localField1.get(localWifiConfiguration);localField1.setAccessible(false);if (localObject2 == null)  return null;Field localField2 = localObject2.getClass().getDeclaredField("SSID");localField2.setAccessible(true);Object localObject3 = localField2.get(localObject2);if (localObject3 == null) return null;localField2.setAccessible(false);String str = (String) localObject3;return str;} catch (Exception localException) {}return null;}/*** 检查是否开启Wifi热点* @return*/public boolean isWifiApEnabled(){try {Method method=mWifiManager.getClass().getMethod("isWifiApEnabled");method.setAccessible(true);return (boolean) method.invoke(mWifiManager);} catch (NoSuchMethodException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();}return false;}/*** 关闭热点*/public void closeWifiAp(){WifiManager wifiManager= (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);if (isWifiApEnabled()){try {Method method=wifiManager.getClass().getMethod("getWifiApConfiguration");method.setAccessible(true);WifiConfiguration config= (WifiConfiguration) method.invoke(wifiManager);Method method2=wifiManager.getClass().getMethod("setWifiApEnabled",WifiConfiguration.class,boolean.class);method2.invoke(wifiManager,config,false);} catch (NoSuchMethodException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();}}}/*** 开热点手机获得其他连接手机IP的方法* @return 其他手机IP 数组列表*/public ArrayList<String> getConnectedIP(){ArrayList<String> connectedIp=new ArrayList<String>();try {BufferedReader br=new BufferedReader(new FileReader("/proc/net/arp"));String line;while ((line=br.readLine())!=null){String[] splitted=line.split(" +");if (splitted !=null && splitted.length>=4){String ip=splitted[0];if (!ip.equalsIgnoreCase("ip")){connectedIp.add(ip);}}}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}return connectedIp;}}

android AP热点(wifi热点)开发相关推荐

  1. Android 11 固定wifi热点名和密码

    Android 11 固定wifi热点名和密码的路径和早期版本也有不同,Android 11 固定wifi热点名和密码的路径方法如下: 1.固定wifi热点名 a.去掉热点明后的SSID --- a/ ...

  2. Android 以太网转 WiFi 热点 (并在同一网段 192.168.0.xx)

    命令如下: 首先打开盒子的 wifi 热点功能,再用以下命令 ip link set eth0 up; ip link add eth1 type bridge ; ip link set eth0 ...

  3. 手机通过笔记本设置AP(wifi 热点)上网 intel5100 agn 无线网卡 win7系统

    手机流量不是太多,总有那么几天不太好受 笔记本可以有线上网,并且有无线网卡,是否可以通过手机连笔记本上网呢. 通过搜索,发现有三种方案可以实现手机通过笔记本上网. 第一种:windows7系统笔记本设 ...

  4. android去掉便携式wifi热点,Android 获取便携式wifi热点开关状态、热点开启与关闭...

    最近做了这两个功能: 1.获取便携式wifi热点开关状态: 2.热点的开启与关闭. 第二个功能就不用说了,百度一搜一大把:第一个功能,在百度基本找不到,最后我是在google找到的,getWifiAp ...

  5. android 11 固定WIFI热点路由器IP

    android11和安卓低版本一样固定WIFI热点路由器IP 的路径不同 这个是在 android11上的修改: --- a/frameworks/base/packages/Tethering/sr ...

  6. android 4g wifi热点,WIFI热点部署+

    WIFI热点部署+4G OK,看完了上面一页也许大家以及和你对WiMax有了一个比较初步的了解.下面让我们来看看HTC EVO 4G在网络方面的支持.进入设置界面,我们先来看看该机的系统版本.   设 ...

  7. xpwifi热点设置android,windowsXP设置wifi热点教程

    <windowsXP设置wifi热点教程>由会员分享,可在线阅读,更多相关<windowsXP设置wifi热点教程(4页珍藏版)>请在人人文库网上搜索. 1.硬件要求:1.带W ...

  8. Android中扫描wifi热点

    1.首先新建了布局模板XML文件vifi.xml,代码很简单,如下: <?xml version="1.0" encoding="utf-8"?> ...

  9. MTK wifi AP mode/wifi 热点模式的相关问题

    [DESCRIPTION] 客户在 wifi 认证测试的过程中,经常需要填写 AP mode/STA mode 下的相关配置资讯, 此 FAQ 特此对常见的问题做一个简要的总结. [SOLUTION] ...

  10. Ubuntu下利用AP架设WIFI热点(含网卡支持查询)

    转载自:http://ihacklog.com/post/use-hostapd-to-setup-wireless-access-point-under-linux.html,向作者表示感谢! 其实 ...

最新文章

  1. redis mysql查询数据类型_linux 常见的标识与Redis数据库详解
  2. Android零基础入门第44节:ListView数据动态更新
  3. 通过性能计数器确定.net应用程序是否存在内存溢出
  4. Application failure. hr=0x80040101:Failed to initialize virtual machine.
  5. 普通行列转换(交叉表,横表变列表)
  6. 卸载一直在创建还原点_Win10电脑开机一直转圈无法进入系统的解决方法
  7. 第一百二十九天 how can I坚持
  8. linux查内存命令6,CentOS 6.8与CentOS 7.5内存查看命令free的差异对比
  9. 如何在 Mac 上安装新字体?
  10. baum welch java_Baum Welch估计HMM参数实例
  11. 全网首发:首个安卓摄像头预览加显示的项目
  12. MatLab 数字图像处理实验 图像分割
  13. 内购 税务信息页填写-新版填写
  14. PTA 6-1 单链表逆转
  15. CRC16 - CCITT 计算方法(查表法)| C语言实现
  16. ROS机器人建模与仿真(一)--URDF机器人建模
  17. js直接打印pdf文件内容
  18. bootstrap-fileinput踩坑-选择文件类型
  19. 影院电影售票管理系统
  20. 用Python爬取知乎上关于程序员的神回复

热门文章

  1. Appium 自动化测试 手机操作
  2. 赚钱的方法分享--首先你要有赚钱的思维和方向计划
  3. 移动硬盘出现好多类似5b823bbe980da233a005c83a\update的文件,0字节,删不掉
  4. 小程序开发(适合初学者)
  5. 北航计算机学院复试专业课科目,2018北航自招复试经历总结
  6. mysql数据库 头像字段_模仿陌陌八张头像的数据库,应该如何建表才合适?
  7. Linux网络新技术基石:eBPF and XDP
  8. python的数据与matlab互通:SciPy
  9. maven打包报错Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.2.RELEASE:repa
  10. 崩坏3卡池模拟器及毕业期望概率计算(含保底)