文档章节

Android Wifi IP 设置

simpower
 simpower
发布于 2014/08/21 19:23
字数 1371
阅读 143
收藏 0
[java]   view plain copy
<EMBED id=ZeroClipboardMovie_1 height=18 name=ZeroClipboardMovie_1 type=application/x-shockwave-flash align=middle pluginspage=http://www.macromedia.com/go/getflashplayer width=18 src=http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf wmode="transparent" flashvars="id=1&width=18&height=18" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" quality="best" menu="false" loop="false">
  1. import java.lang.reflect.Constructor;  
  2. import java.lang.reflect.Field;  
  3. import java.lang.reflect.InvocationTargetException;  
  4. import java.net.InetAddress;  
  5. import java.util.ArrayList;  
  6. import java.util.List;  
  7.   
  8. import android.app.Activity;  
  9. import android.app.AlertDialog;  
  10. import android.content.BroadcastReceiver;  
  11. import android.content.Context;  
  12. import android.content.DialogInterface;  
  13. import android.content.IntentFilter;  
  14. import android.net.wifi.ScanResult;  
  15. import android.net.wifi.WifiConfiguration;  
  16. import android.net.wifi.WifiManager;  
  17. import android.net.wifi.p2p.WifiP2pManager;  
  18. import android.net.wifi.p2p.WifiP2pManager.Channel;  
  19. import android.os.Bundle;  
  20. import android.text.TextUtils;  
  21. import android.view.LayoutInflater;  
  22. import android.view.View;  
  23. import android.view.View.OnClickListener;  
  24. import android.widget.EditText;  
  25. import android.widget.ImageButton;  
  26. import android.widget.ListView;  
  27. import android.widget.Toast;  
  28.   
  29. public class WifiActivity extends Activity implements OnClickListener{  
  30.     protected static final String TAG = "WifiActivity";  
  31.       
  32.     public final static String KEY_WIFI_PRIORITY = "wifi_priority";  
  33.     public final static String KEY_WIFI_STATIC_IP = "wifi_static_ip";  
  34.       
  35.     WifiP2pManager mManager;  
  36.     Channel mChannel;  
  37.     BroadcastReceiver mReceiver;  
  38.     IntentFilter mIntentFilter;  
  39.     private WifiManager mWifiManager;  
  40.     private List<ScanResult> mListResult;  
  41.     private WifiAdapter mWifiAdapter;  
  42.     private ListView mList;  
  43.       
  44.     /** Called when the activity is first created. */  
  45.     @Override  
  46.     public void onCreate(Bundle savedInstanceState) {  
  47.         super.onCreate(savedInstanceState);  
  48.         setContentView(R.layout.wifi_list);  
  49.         ImageButton btn = (ImageButton)findViewById(R.id.back);  
  50.         btn.setOnClickListener(this);  
  51.         mList = (ListView)findViewById(R.id.list_view);  
  52.         mReceiver = new WifiReceiver(new WifiScanListener() {  
  53.               
  54.             @Override  
  55.             public void suppStateChange() {  
  56.                   
  57.             }  
  58.               
  59.             @Override  
  60.             public void stateChange() {  
  61.                   
  62.             }  
  63.               
  64.             @Override  
  65.             public void endScan() {  
  66.                 endScanWifi(mWifiManager.getScanResults());               
  67.             }  
  68.         });  
  69.           
  70.         mIntentFilter = new IntentFilter();  
  71.           
  72.         mIntentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");  
  73.         mIntentFilter.addAction("android.net.wifi.SCAN_RESULTS");  
  74.         mIntentFilter.addAction("android.net.wifi.supplicant.STATE_CHANGE");  
  75.           
  76.         mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);          
  77.         mWifiManager.setWifiEnabled(true);  
  78.         mWifiAdapter = new WifiAdapter(thisnull);  
  79.         mList.setAdapter(mWifiAdapter);  
  80.           
  81.     }  
  82.       
  83. //    void showLog(String msg) {  
  84. //      new AlertDialog.Builder(this).setTitle(R.string.alert_dialog_prompt).setMessage(msg).show();  
  85. //  }  
  86.   
  87.     void promptMessage(String msg) {  
  88.         Toast.makeText(this, msg, Toast.LENGTH_LONG).show();  
  89.     }  
  90.       
  91.     public void showEditWifi(final ScanResult sr){  
  92.         LayoutInflater factory = LayoutInflater.from(this);  
  93.         final View textEntryView = factory.inflate(R.layout.dialog_wifi_setting, null);  
  94.         new AlertDialog.Builder(this).setIconAttribute(android.R.attr.dialogIcon).setTitle(sr.SSID).setView(textEntryView).setCancelable(false)  
  95.                 .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {  
  96.                     public void onClick(DialogInterface dialog, int whichButton) {  
  97.                         try {  
  98.                             EditText edtWifiPwd = (EditText) textEntryView.findViewById(R.id.edt_wifi_pwd);  
  99.                             EditText edtStaticIp = (EditText) textEntryView.findViewById(R.id.edt_static_ip);  
  100.                             EditText edtStaticGateway = (EditText) textEntryView.findViewById(R.id.edt_static_gateway);  
  101.                             EditText edtStaticNetmask = (EditText) textEntryView.findViewById(R.id.edt_static_netmask);  
  102.                             EditText edtStaticDns = (EditText) textEntryView.findViewById(R.id.edt_static_dns);  
  103.                               
  104.                             String wifiPwd = edtWifiPwd.getText().toString().trim();  
  105.                             String ip = edtStaticIp.getText().toString().trim();  
  106.                             String gateway = edtStaticGateway.getText().toString().trim();  
  107.                             String prefixLength = edtStaticNetmask.getText().toString().trim();  
  108.                             String dns = edtStaticDns.getText().toString().trim();  
  109.                               
  110.                             saveStaticWifiConfig(sr,wifiPwd,ip,Integer.parseInt(prefixLength));  
  111.                         }catch (IllegalArgumentException e) {  
  112.                             promptMessage(getString(R.string.system_wifi_ip_error));  
  113.                         } catch (Exception e) {  
  114.                             e.printStackTrace();  
  115.                             promptMessage(getString(R.string.system_wifi_setting_error));  
  116.                         }  
  117.                     }  
  118.                 }).setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {  
  119.                     public void onClick(DialogInterface dialog, int whichButton) {  
  120.                         dialog.cancel();  
  121.                     }  
  122.                 }).create().show();  
  123.           
  124.         try {  
  125.             WifiConfiguration historyWifiConfig = getHistoryWifiConfig(sr.SSID);  
  126.             EditText edtWifiPwd = (EditText) textEntryView.findViewById(R.id.edt_wifi_pwd);  
  127.             EditText edtStaticIp = (EditText) textEntryView.findViewById(R.id.edt_static_ip);  
  128.             EditText edtStaticGateway = (EditText) textEntryView.findViewById(R.id.edt_static_gateway);  
  129.             EditText edtStaticNetmask = (EditText) textEntryView.findViewById(R.id.edt_static_netmask);  
  130.             EditText edtStaticDns = (EditText) textEntryView.findViewById(R.id.edt_static_dns);  
  131.               
  132.             if(historyWifiConfig != null){            
  133.                 InetAddress address = getIpAddress(historyWifiConfig);  
  134.                 if(address != null){  
  135.                     edtStaticIp.setText(address.getHostAddress());  
  136.                     address = null;  
  137.                 }  
  138.                 address = getGateway(historyWifiConfig);  
  139.                 if(address != null){  
  140.                     edtStaticGateway.setText(address.getHostAddress());  
  141.                     address = null;  
  142.                 }  
  143.                 address = getDNS(historyWifiConfig);  
  144.                 if(address != null){  
  145.                     edtStaticDns.setText(address.getHostAddress());  
  146.                     address = null;  
  147.                 }  
  148.                 edtStaticNetmask.setText(getNetworkPrefixLength(historyWifiConfig));              
  149.                   
  150.             }  
  151.               
  152.             if(TextUtils.isEmpty(edtStaticIp.getText().toString().trim())){  
  153.                 String ipString = SmartHomePreference.getStringProperty(KEY_WIFI_STATIC_IP);  
  154.                 int intIp = inetAddressToInt(InetAddress.getByName(ipString));   
  155.                 String dns = (intIp & 0xFF ) + "." + ((intIp >> 8 ) & 0xFF) + "." + ((intIp >> 16 ) & 0xFF) + ".1";  
  156.                   
  157.                 edtStaticIp.setText(ipString);  
  158.                 edtStaticNetmask.setText("24");  
  159.                 edtStaticGateway.setText(dns);  
  160.                 edtStaticDns.setText(dns);                
  161.             }  
  162.         } catch (Exception e) {  
  163.             e.printStackTrace();  
  164.         }  
  165.           
  166.     }  
  167.       
  168.     /** 
  169.      * 设置wifi,编辑静态IP 
  170.      * @param sr 
  171.      * @param pwd 
  172.      * @param ip 
  173.      * @throws Exception 
  174.      */  
  175.     public void saveStaticWifiConfig(final ScanResult sr,String pwd, String ip,int networkPrefixLength) throws Exception{    
  176.         InetAddress intetAddress  = InetAddress.getByName(ip);  
  177.         int intIp = inetAddressToInt(intetAddress);       
  178.         WifiConfiguration historyWifiConfig = getHistoryWifiConfig(sr.SSID);              
  179.         if(historyWifiConfig == null){  
  180.             historyWifiConfig = createComWifiConfig(sr.SSID,pwd);             
  181.         }else{  
  182.             if(!TextUtils.isEmpty(pwd)){  
  183.                 historyWifiConfig.preSharedKey = "\""+ pwd + "\"";    
  184.             }  
  185.         }  
  186.           
  187.         String dns = (intIp & 0xFF ) + "." + ((intIp >> 8 ) & 0xFF) + "." + ((intIp >> 16 ) & 0xFF) + ".1";  
  188.         setIpAssignment("STATIC", historyWifiConfig); //"STATIC" or "DHCP" for dynamic setting  
  189.         setIpAddress(intetAddress, networkPrefixLength, historyWifiConfig);  
  190.         setGateway(InetAddress.getByName(dns), historyWifiConfig);  
  191.         setDNS(InetAddress.getByName(dns), historyWifiConfig);            
  192.           
  193.         mWifiManager.removeNetwork(historyWifiConfig.networkId);  
  194.         int netId = mWifiManager.addNetwork(historyWifiConfig);  
  195.         mWifiManager.enableNetwork(netId, true);  
  196.         mWifiManager.updateNetwork(historyWifiConfig); //apply the setting  
  197.         SmartHomePreference.setProperty(WifiActivity.KEY_WIFI_PRIORITY, sr.SSID);  
  198.           
  199.         mWifiManager.startScan();  
  200.     }  
  201.       
  202.       
  203.     /*** 
  204.      * Convert a IPv4 address from an InetAddress to an integer 
  205.      * @param inetAddr is an InetAddress corresponding to the IPv4 address 
  206.      * @return the IP address as an integer in network byte order 
  207.      */  
  208.     public static int inetAddressToInt(InetAddress inetAddr)  
  209.             throws IllegalArgumentException {  
  210.         byte [] addr = inetAddr.getAddress();  
  211.         if (addr.length != 4) {  
  212.             throw new IllegalArgumentException("Not an IPv4 address");  
  213.         }  
  214.         return ((addr[3] & 0xff) << 24) | ((addr[2] & 0xff) << 16) |  
  215.                 ((addr[1] & 0xff) << 8) | (addr[0] & 0xff);  
  216.     }  
  217.       
  218.     public void editStaticWifiConfig(final ScanResult sr,String pwd, String ip, String gateway,int prefixLength,String dns) throws Exception{          
  219.         WifiConfiguration historyWifiConfig = getHistoryWifiConfig(sr.SSID);  
  220.           
  221.         if(historyWifiConfig == null){  
  222.             historyWifiConfig = createComWifiConfig(sr.SSID,pwd);  
  223.             int netId = mWifiManager.addNetwork(historyWifiConfig);  
  224.             mWifiManager.enableNetwork(netId, true);  
  225.         }  
  226.           
  227.         setIpAssignment("STATIC", historyWifiConfig); //"STATIC" or "DHCP" for dynamic setting  
  228.         setIpAddress(InetAddress.getByName(ip), prefixLength, historyWifiConfig);  
  229.         setGateway(InetAddress.getByName(gateway), historyWifiConfig);  
  230.         setDNS(InetAddress.getByName(dns), historyWifiConfig);  
  231.           
  232.         mWifiManager.updateNetwork(historyWifiConfig); //apply the setting  
  233.     }  
  234.       
  235.     public void editDhcpWifiConfig(final ScanResult sr,String pwd) throws Exception{          
  236.         WifiConfiguration historyWifiConfig = getHistoryWifiConfig(sr.SSID);  
  237.           
  238.         if(historyWifiConfig == null){  
  239.             historyWifiConfig = createComWifiConfig(sr.SSID,pwd);  
  240.             int netId = mWifiManager.addNetwork(historyWifiConfig);  
  241.             mWifiManager.enableNetwork(netId, true);  
  242.         }  
  243.           
  244.         setIpAssignment("DHCP", historyWifiConfig); //"STATIC" or "DHCP" for dynamic setting  
  245.           
  246.         mWifiManager.updateNetwork(historyWifiConfig); //apply the setting  
  247.     }  
  248.   
  249.     /** 
  250.      *  新建wifi配置项 
  251.      * @param ssid 
  252.      * @param pwd 
  253.      * @return 
  254.      */  
  255.     public WifiConfiguration createComWifiConfig(String ssid,String pwd){  
  256.         WifiConfiguration wc = new WifiConfiguration();  
  257.         wc.SSID = "\"" + ssid + "\"";                   //配置wifi的SSID,即该热点的名称,如:TP-link_xxx  
  258.         wc.preSharedKey = "\""+ pwd + "\"";            //该热点的密码  
  259.         wc.hiddenSSID = true;  
  260.         wc.status = WifiConfiguration.Status.ENABLED;  
  261.         wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);  
  262.         wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);  
  263.         wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);  
  264.         wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);  
  265.         wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);  
  266.         wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);  
  267.         return wc;  
  268.     }  
  269.       
  270.     /** 
  271.      * 查找已经设置好的Wifi 
  272.      * @param ssid 
  273.      * @return 
  274.      */  
  275.     public WifiConfiguration getHistoryWifiConfig(String ssid){  
  276.         List<WifiConfiguration> localList = mWifiManager.getConfiguredNetworks();  
  277.         for(WifiConfiguration wc : localList){  
  278.             if(("\"" + ssid + "\"").equals(wc.SSID)){  
  279.                 return wc;  
  280.             }  
  281.             mWifiManager.disableNetwork(wc.networkId);  
  282.         }  
  283.         return null;  
  284.     }  
  285.     
  286.     public static void setIpAssignment(String assign, WifiConfiguration wifiConf)throws SecurityException, IllegalArgumentException,NoSuchFieldException, IllegalAccessException {  
  287.         setEnumField(wifiConf, assign, "ipAssignment");  
  288.     }  
  289.   
  290.     public static void setIpAddress(InetAddress addr, int prefixLength,WifiConfiguration wifiConf) throws SecurityException,IllegalArgumentException,  
  291.     NoSuchFieldException,IllegalAccessException, NoSuchMethodException,ClassNotFoundException, InstantiationException,InvocationTargetException {  
  292.         Object linkProperties = getField(wifiConf, "linkProperties");  
  293.         if (linkProperties == null)  
  294.             return;  
  295.         Class laClass = Class.forName("android.net.LinkAddress");  
  296.         Constructor laConstructor = laClass.getConstructor(new Class[] {InetAddress.classint.class });  
  297.         Object linkAddress = laConstructor.newInstance(addr, prefixLength);  
  298.         ArrayList mLinkAddresses = (ArrayList) getDeclaredField(linkProperties,"mLinkAddresses");  
  299.         mLinkAddresses.clear();  
  300.         mLinkAddresses.add(linkAddress);  
  301.     }  
  302.   
  303.     public static void setGateway(InetAddress gateway,WifiConfiguration wifiConf) throws SecurityException,IllegalArgumentException,  
  304.     NoSuchFieldException,IllegalAccessException, ClassNotFoundException,NoSuchMethodException, InstantiationException,InvocationTargetException {  
  305.         Object linkProperties = getField(wifiConf, "linkProperties");  
  306.         if (linkProperties == null)  
  307.             return;  
  308.         Class routeInfoClass = Class.forName("android.net.RouteInfo");  
  309.         Constructor routeInfoConstructor = routeInfoClass.getConstructor(new Class[] { InetAddress.class });  
  310.         Object routeInfo = routeInfoConstructor.newInstance(gateway);  
  311.         ArrayList mRoutes = (ArrayList) getDeclaredField(linkProperties,"mRoutes");  
  312.         mRoutes.clear();  
  313.         mRoutes.add(routeInfo);  
  314.     }  
  315.   
  316.     public static void setDNS(InetAddress dns, WifiConfiguration wifiConf) throws SecurityException, IllegalArgumentException,NoSuchFieldException, IllegalAccessException {  
  317.         Object linkProperties = getField(wifiConf, "linkProperties");  
  318.         if (linkProperties == null)  
  319.             return;  
  320.         ArrayList<InetAddress> mDnses = (ArrayList<InetAddress>) getDeclaredField(linkProperties, "mDnses");  
  321.         mDnses.clear(); // or add a new dns address , here I just want to replace DNS1  
  322.         mDnses.add(dns);  
  323.     }  
  324.       
  325.     public static String getNetworkPrefixLength(WifiConfiguration wifiConf) {  
  326.         String address = "";  
  327.         try {  
  328.             Object linkProperties = getField(wifiConf, "linkProperties");  
  329.             if (linkProperties == null)  
  330.                 return null;  
  331.               
  332.             if (linkProperties != null){  
  333.                 ArrayList mLinkAddresses = (ArrayList) getDeclaredField(linkProperties,"mLinkAddresses");  
  334.                 if(mLinkAddresses != null && mLinkAddresses.size() > 0){  
  335.                     Object linkAddressObj = mLinkAddresses.get(0);  
  336.                     address = linkAddressObj.getClass().getMethod("getNetworkPrefixLength",  new Class[]{}).invoke(linkAddressObj,null) + "";  
  337.                 }  
  338.             }  
  339.               
  340.         } catch (Exception e) {  
  341.             e.printStackTrace();  
  342.         }  
  343.         return address;  
  344.     }  
  345.       
  346.     public static InetAddress getIpAddress(WifiConfiguration wifiConf) {  
  347.         InetAddress address = null;  
  348.         try {  
  349.             Object linkProperties = getField(wifiConf, "linkProperties");  
  350.             if (linkProperties == null)  
  351.                 return null;  
  352.               
  353.             if (linkProperties != null){  
  354.                 ArrayList mLinkAddresses = (ArrayList) getDeclaredField(linkProperties,"mLinkAddresses");  
  355.                 if(mLinkAddresses != null && mLinkAddresses.size() > 0){  
  356.                     Object linkAddressObj = mLinkAddresses.get(0);  
  357.                     address = (InetAddress)linkAddressObj.getClass().getMethod("getAddress",  new Class[]{}).invoke(linkAddressObj,null);  
  358.                 }  
  359.             }  
  360.               
  361.         } catch (Exception e) {  
  362.             e.printStackTrace();  
  363.         }  
  364.         return address;  
  365.     }  
  366.   
  367.     public static InetAddress getGateway(WifiConfiguration wifiConf)  {  
  368.         InetAddress address = null;  
  369.         try {  
  370.             Object linkProperties = getField(wifiConf, "linkProperties");  
  371.               
  372.             if (linkProperties != null){  
  373.                 ArrayList mRoutes = (ArrayList) getDeclaredField(linkProperties,"mRoutes");  
  374.                 if(mRoutes != null && mRoutes.size() > 0){  
  375.                     Object linkAddressObj = mRoutes.get(0);  
  376.                     address = (InetAddress)linkAddressObj.getClass().getMethod("getGateway",  new Class[]{}).invoke(linkAddressObj,null);  
  377.                 }  
  378.             }  
  379.         } catch (Exception e) {  
  380.             e.printStackTrace();  
  381.         }  
  382.         return address;  
  383.     }  
  384.   
  385.     public static InetAddress getDNS(WifiConfiguration wifiConf) {  
  386.         InetAddress address = null;  
  387.         try {  
  388.             Object linkProperties = getField(wifiConf, "linkProperties");  
  389.               
  390.             if (linkProperties != null){  
  391.                 ArrayList<InetAddress> mDnses = (ArrayList<InetAddress>) getDeclaredField(linkProperties, "mDnses");  
  392.                 if(mDnses != null && mDnses.size() > 0){  
  393.                     address = (InetAddress)mDnses.get(0);                 
  394.                 }  
  395.             }         
  396.         } catch (Exception e) {  
  397.             e.printStackTrace();  
  398.         }  
  399.           
  400.         return address;  
  401.     }  
  402.   
  403.     public static Object getField(Object obj, String name) throws SecurityException, NoSuchFieldException,IllegalArgumentException, IllegalAccessException {  
  404.         Field f = obj.getClass().getField(name);  
  405.         Object out = f.get(obj);  
  406.         return out;  
  407.     }  
  408.   
  409.     public static Object getDeclaredField(Object obj, String name) throws SecurityException, NoSuchFieldException,IllegalArgumentException, IllegalAccessException {  
  410.         Field f = obj.getClass().getDeclaredField(name);  
  411.         f.setAccessible(true);  
  412.         Object out = f.get(obj);  
  413.         return out;  
  414.     }  
  415.   
  416.     public static void setEnumField(Object obj, String value, String name) throws SecurityException, NoSuchFieldException,  
  417.             IllegalArgumentException, IllegalAccessException {  
  418.         Field f = obj.getClass().getField(name);  
  419.         f.set(obj, Enum.valueOf((Class<Enum>) f.getType(), value));  
  420.     }  
  421.   
  422.   
  423.     @Override  
  424.     protected void onResume() {  
  425.         super.onResume();  
  426.         registerReceiver(mReceiver, mIntentFilter);  
  427.         if(mWifiManager != null) mWifiManager.startScan();  
  428.     }  
  429.       
  430.     @Override  
  431.     protected void onPause() {  
  432.         super.onPause();  
  433.         unregisterReceiver(mReceiver);          
  434.     }  
  435.   
  436.     @Override  
  437.     public void onClick(View v) {  
  438.         switch (v.getId()) {  
  439.         case R.id.back:  
  440. //          if(mWifiManager != null) mWifiManager.startScan();  
  441.             finish();  
  442.             break;  
  443.   
  444.         default:  
  445.             break;  
  446.         }  
  447.     }  
  448.       
  449.     public void endScanWifi(final List<ScanResult> list){  
  450.         runOnUiThread(new Runnable() {            
  451.             @Override  
  452.             public void run() {  
  453.                 if(mWifiAdapter != null){  
  454.                     mWifiAdapter.setList(list);  
  455.                     mWifiAdapter.notifyDataSetChanged();  
  456.                 }     
  457.             }  
  458.         });  
  459.               
  460.     }  
  461. }  


本文转载自:http://blog.csdn.net/arescj/article/details/7981370

simpower
粉丝 28
博文 659
码字总数 47375
作品 0
海淀
程序员
私信 提问
ADB通过WIFI连接Android设备

ADB通过WIFI连接Android设备 有些设备不支持WiFi调试,关闭了,那是没有办法的,我手上的几个手机都可以,但是同事的华为的手机就....... 通常情况下,我们都通过USB线连接Android设备,以此...

iSnowFlake
2015/08/18
3.6K
0
Android手机通过电脑上网的几种方法

本文定位:没有wifi,想让手机通过电脑的有线连接上网。 android手机可以通过wifi上网,这个很好。可当没有wifi的时候怎么上啊,3G--->流量受限,看视频很不划算! 我这里总结了几种方法供大...

长平狐
2012/06/08
850
2
android4.0 WIFI实现网络连接

android4.0上打开wifi后,自动扫描附近所有的wifi热点,连接指定的wifi名称和密码,DHCP动态获取IP后,最后使用Ping命令对连网进行测试。 1.注册wifi的广播接收器: 监听WifiManager.WIFISTA...

_liusl
2013/11/12
12K
0
Android各种Manager-郭通

一、PowerManager 主要是用来控制电源状态,设置屏幕状态,和电池待机状态 PowerManager pm = ((PowerManager)getSystemService(POWER_SERVICE)); 这里我需要保持屏幕长期唤醒,不被锁屏,所...

蓝神100
2018/06/28
0
0
请教大神,LayoutInflater和View.linflate出来的Layout不能操作

3天前已经发过一个帖子了。 http://www.eoeandroid.com/thread-295192-1-1.html 没有获得解决办法,故此继续过来询问 问题描述:此APP模仿微信底部用的OnPageChangeLisenter实现的。并没有采...

茄屋多萝
2013/07/23
4.4K
0

没有更多内容

加载失败,请刷新页面

加载更多

springboot2.0 maven打包分离lib,resources

springboot将工程打包成jar包后,会出现获取classpath下的文件出现测试环境正常而生产环境文件找不到的问题,这是因为 1、在调试过程中,文件是真实存在于磁盘的某个目录。此时通过获取文件路...

陈俊凯
今天
5
0
BootStrap

一、BootStrap 简洁、直观、强悍的前端开发框架,让web开发更加迅速、简单 中文镜像网站:http://www.bootcss.com 用于开发响应式布局、移动设备优先的WEB项目 1、使用boot 创建文件夹,在文...

wytao1995
今天
9
0
小知识:讲述Linux命令别名与资源文件的区别

别名 别名是命令的快捷方式。为那些需要经常执行,但需要很长时间输入的长命令创建快捷方式很有用。语法是: alias ppp='ping www.baidu.com' 它们并不总是用来缩短长命令。重要的是,你将它...

老孟的Linux私房菜
今天
8
0
《JAVA核心知识》学习笔记(6. Spring 原理)-5

它是一个全面的、企业应用开发一站式的解决方案,贯穿表现层、业务层、持久层。但是 Spring 仍然可以和其他的框架无缝整合。 6.1.1. Spring 特点 6.1.1.1. 轻量级 6.1.1.2. 控制反转 6.1.1....

Shingfi
今天
7
0
Excel导入数据库数据+Excel导入网页数据【实时追踪】

1.Excel导入数据库数据:数据选项卡------>导入数据 2.Excel导入网页数据【实时追踪】:

东方墨天
今天
10
1

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部