神刀安全网

Manage wireless access points in Android

accesspoint

Manage wireless access points in Android

Manage wireless access points on Android 2.2 or later.

Quick start

repositories {     jcenter() }  dependencies {     compile 'cc.mvdan.accesspoint:library:0.2.0' }
import cc.mvdan.accesspoint.WifiApControl;  WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiApControl apControl = WifiApControl.getInstance(context);  boolean enabled = apControl.isEnabled(); int state = apControl.getState();  WifiConfiguration config = apControl.getConfiguration(); Inet4Address addr4 = apControl.getInet4Address(); Inet6Address addr6 = apControl.getInet6Address();  // These are cached and may no longer be connected, see // WifiApControl.getReachableClients(int, ReachableClientListener) List<WifiApControl.Client> clients = apControl.getClients()  // Wifi must be disabled to enable the access point wifiManager.setWifiEnabled(false); apControl.enable();  apControl.disable(); wifiManager.setWifiEnabled(true);

Remember to ask for WRITE_SETTINGS on 6.0+! The example app has a sample implementation of that. The library will not do this for you, as it involves UI interaction that should be handled and customizable by your app.

Features

  • Enabling and disabling your AP
  • Configuring your AP via WifiConfiguration
  • Getting your device’s IP address in your AP network
  • Getting the list of clients connected to your AP

Permissions

You will need the following:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WRITE_SETTINGS"/>

How does it work?

Enabling, disabling and configuring of wireless Access Points are all unaccessible in the SDK behind hidden methods in WifiManager . Reflection is used to get access to those methods.

Getting your own IP address is done by getting the IP address that is associated with the wireless network interface.

Getting the list of clients consists of parsing /proc/net/arp and parsing each line to see what devices are neighbours in our wireless network.

An extra method is available to get the list of reachable clients, since the arp table is cached for up to a few minutes. The method asynchronously tests the reachability of each client.

License

Published under the Apache2 license.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Manage wireless access points in Android

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮