Android-如何编写Wifi访问点到xml文件?

时间:2013-12-23 08:50:45

标签: android wifi

如何将Wifi访问点写入xml文件?

3 个答案:

答案 0 :(得分:0)

您可以使用此代码获取wifi信息 -

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
wifiInfo.getBSSID();
wifiInfo.getIpAddress();
wifiInfo.getMacAddress();
wifiInfo.getSSID();
wifiInfo.getNetworkId();

用于写入xml文件refer this

答案 1 :(得分:0)

   WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
   WifiInfo wifiInfo = wifiManager.getConnectionInfo();
   wifiInfo.getBSSID();
   wifiInfo.getIpAddress();
   wifiInfo.getMacAddress();
   wifiInfo.getSSID();
   wifiInfo.getNetworkId();

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                .newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory
                .newDocumentBuilder();
        org.w3c.dom.Document doc = documentBuilder.newDocument();



        org.w3c.dom.Element root = doc
                .createElement("wifiInfo");

        doc.appendChild(root);

        org.w3c.dom.Element bssIdNode = doc
                .createElement("bssId");

        bssIdNode.appendChild(doc.createTextNode(bssId));
        root.appendChild(bssIdNode);

        org.w3c.dom.Element ipAddNode = doc
                .createElement("ipAdd");
        ipAddNode.appendChild(doc.createTextNode(ipAdd));
        root.appendChild(bssIdNode);



        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT,
                "Yes");

        StringWriter sw = new StringWriter();
        StreamResult result = new StreamResult(sw);
        DOMSource source = new DOMSource(doc);
        transformer.transform(source, result);
         xmlString = sw.toString();

答案 2 :(得分:0)

对于#1的建议,它只能获取当前连接的网络信息。 以下代码段可能符合您的要求:

WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> mAPList = wm.getScanResult();
for (ScanResult sr : mAPList) {
    //TO-DO
}

不要忘记在manifest.xml中添加android.permission.ACCESS_WIFI_STATE