Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • android 热点

    post by onelong / 2015-8-2 0:48 Sunday [android]

    最近要做一个热点App,类似快牙。也是这样看系统的Settings代码,做点笔记吧。创建配置对象:

    public WifiConfiguration getConfig(int type,String ssid,String password) {

            WifiConfiguration config = new WifiConfiguration();

            config.SSID = ssid;

            switch (type) {

                case TYPE_OPEN:

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

                    return config;

                case TYPE_WPA:

                    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);

                    config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);

                    config.preSharedKey = password;

                    return config;

                case TYPE_WPA2:

                //WPA2_PSK==4

                    config.allowedKeyManagement.set(4);

                    config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);

                    config.preSharedKey = password;

                    return config;

            }

            return null;

     

        }

    WEP的配置没有支持。

    通过发射打开关闭AP,获取Ap的状态

    public void stratWifiAp(WifiManager wifiManager, String ssid, String pass,

    int type, boolean hiddenSSID) {

     

    Method method1 = null;

    try {

    method1 = wifiManager.getClass().getMethod("setWifiApEnabled",

    WifiConfiguration.class, Boolean.TYPE);

    // method1 = wifiManager.getClass().getMethod("setWifiApEnabled",

    // WifiConfiguration.class, boolean.class);

    WifiConfiguration netConfig = getConfig(type, ssid, pass);

    Object obj = method1.invoke(wifiManager, netConfig, true);

    System.out.println("--stratWifiAp--"+obj);

    getWifiApState(wifiManager);

    } catch (Exception e) {

    e.printStackTrace();

     

    }

     

    public void closeWifiAp(WifiManager wifiManager) {

     

    Method method1 = null;

    try {

    method1 = wifiManager.getClass().getMethod("setWifiApEnabled",

    WifiConfiguration.class, Boolean.TYPE);

    Object obj = method1.invoke(wifiManager, null, false);

    System.out.println("--closeWifiAp--"+obj);

    getWifiApState(wifiManager);

    } catch (Exception e) {

    e.printStackTrace();

    }

     

    }

     

    public int getWifiApState(WifiManager wifiManager) {

    try {

    Method method = wifiManager.getClass().getMethod("getWifiApState");

    // method.setAccessible(true);

    int i = (Integer) method.invoke(wifiManager);

    System.out.println("wifi state:  " + i);

    return i;

    } catch (Exception e) {

    // Log.i("Cannot get WiFi AP state" + e);

    return WIFI_AP_STATE_FAILED;

    }

     

    }

    这些网上都很多教程。怎样获取连接的客户端呢?

    getHotspotClients

    阻止某个mac连接

     

    blockClient

    下面是测试代码

    try {

    Method method = wifiManager.getClass().getMethod("getHotspotClients");

    List<Object> items = (List<Object>) method.invoke(wifiManager);

     

    System.out.println(items+"");

     

    if(items.size()>0)

    {

    Object tt = items.get(0);

     

    Method method1 = wifiManager.getClass().getMethod("blockClient",

    tt.getClass());

    tt = method1.invoke(wifiManager,tt);

     

    System.out.println(""+tt);

    /*

    Field[] classMethods = null;

            try {

                classMethods = tt.getClass().getDeclaredFields();

            } catch(SecurityException e) {

            //System.out.println( "getDeclaredMethods failed");

            }      

            for (int i = 0;i < classMethods.length; i++)

            {

                System.out.println( "found api: "+ classMethods[i].getName());

               

            } */   

    }

     

    } catch (Exception e) {

    e.printStackTrace();

     

    }

    下面是反射WifiManager 发现的api

    ound api: addNetwork

     found api: addToBlacklist

     found api: blockClient—  阻止某个客户端,参数是HotspotClient,是系统的隐藏api

     found api: cancelWps

     found api: clearBlacklist

     found api: connect

     found api: connect

     found api: connectWithWpsPin

     found api: createMulticastLock

     found api: createWifiLock

     found api: createWifiLock

     found api: disable

     found api: disableNetwork

      found api: disconnect

      found api: doCtiaTestOff

      found api: doCtiaTestOn

      found api: doCtiaTestRate

      found api: enableAggressiveHandover

      found api: enableNetwork

      found api: enableVerboseLogging

      found api: finalize

      found api: forget

      found api: getAccessPointPreferredChannels

      found api: getAggressiveHandover

      found api: getAllowScansWithTraffic

      found api: getBatchedScanResults

      found api: getChannelList

      found api: getClientIp— 获取客户端的ip

      found api: getConfigFile

      found api: getConfiguredNetworks

      found api: getConnectionInfo

      found api: getConnectionStatistics

      found api: getControllerActivityEnergyInfo

      found api: getCredFromNfc

      found api: getDhcpInfo

      found api: getFrequencyBand

      found api: getHotspotClients——获取所有客户端

      found api: getPPPOEInfo

      found api: getPinFromNfc

      found api: getPoorLinkThreshold

      found api: getPrivilegedConfiguredNetworks

      found api: getScanResults

      found api: getTxPacketCount

      found api: getVerboseLoggingLevel

      found api: getWifiApConfiguration

      found api: getWifiApState

      found api: getWifiServiceMessenger

      found api: getWifiState

      found api: getWifiStatus

      found api: getWpsCredAndConnect

      found api: getWpsNfcConfigurationToken

      found api: initializeMulticastFiltering

      found api: is5GHzBandSupported

      found api: is5gBandSupported

      found api: isAdditionalStaSupported

      found api: isBatchedScanSupported

      found api: isDeviceToApRttSupported

      found api: isDeviceToDeviceRttSupported

      found api: isDualBandSupported

      found api: isEnhancedPowerReportingSupported

      found api: isMulticastEnabled

      found api: isNanSupported

      found api: isOffChannelTdlsSupported

      found api: isP2pSupported

      found api: isPasspointSupported

      found api: isPortableHotspotSupported

      found api: isPreferredNetworkOffloadSupported

      found api: isScanAlwaysAvailable

      found api: isSuitableForTest

      found api: isTdlsSupported

      found api: isWifiApEnabled

      found api: isWifiEnabled

      found api: isWifiScannerSupported

      found api: pingSupplicant

      found api: pollBatchedScan

      found api: reassociate

      found api: reconnect

      found api: removeNetwork

      found api: requestBatchedScan

      found api: requestBatchedScan

      found api: save

      found api: saveConfiguration

      found api: setAllowScansWithTraffic

      found api: setApProbeRequestEnabled

      found api: setAutoJoinScanWhenConnected

      found api: setCountryCode

      found api: setFrequencyBand

      found api: setHotspotOptimization

      found api: setPoorLinkProfilingOn

      found api: setPoorLinkThreshold

      found api: setPowerSavingMode

      found api: setTdlsEnabled

      found api: setTdlsEnabledWithMacAddress

      found api: setTxPower

      found api: setTxPowerEnabled

      found api: setWifiApConfiguration

      getGenericParameterTypes:class android.net.wifi.WifiConfiguration

      found api: setWifiApEnabled

      found api: setWifiEnabled

      found api: setWoWlanMagicMode

      found api: setWoWlanNormalMode

      found api: startApWps

      found api: startCustomizedScan

      found api: startCustomizedScan

      found api: startPPPOE

      found api: startScan

      found api: startScan

      found api: startWifi

      found api: startWps

      found api: startWpsExternalRegistrar

      found api: startWpsRegistrar

      found api: stopBatchedScan

      found api: stopPPPOE

      found api: stopReconnectAndScan

      found api: stopWifi

      found api: suspendNotification

      found api: unblockClient—-解除阻止

      found api: updateNetwork

      found api: writeCredToNfc

      found api: writePinToNfc

      found api: access$000

      found api: access$100

      found api: access$102

      found api: access$200

      found api: access$300

      found api: access$400

      found api: access$500

      found api: access$508

      found api: access$510

      found api: addOrUpdateNetwork

      found api: calculateSignalLevel

      found api: compareSignalLevel

      found api: getSupportedFeatures

      found api: init

      found api: isFeatureSupported

      found api: putListener

      found api: removeListener

      found api: validateChannel

    标签: android android
    引用地址:
     

    我要评论