- WifiManager wm = (WifiManager)getSystemService(WIFI_SERVICE);
- DhcpInfo di = wm.getDhcpInfo();
- long getewayIpL=di.gateway;
- String getwayIpS=long2ip(getewayIpL);//网关地址
- long netmaskIpL=di.netmask;
- String netmaskIpS=long2ip(netmaskIpL);//子网掩码地址
- String long2ip(long ip){
- StringBuffer sb=new StringBuffer();
- sb.append(String.valueOf((int)(ip&0xff)));
- sb.append('.');
- sb.append(String.valueOf((int)((ip>>8)&0xff)));
- sb.append('.');
- sb.append(String.valueOf((int)((ip>>16)&0xff)));
- sb.append('.');
- sb.append(String.valueOf((int)((ip>>24)&0xff)));
- return sb.toString();
- }
- //注意添加权限
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
public class MainActivity extends Activity { ActionBar actionBar; //声明ActionBar @Override protected void onCreate( Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView( R .layout.activity_main); actionBar = getSupportActionBar(); //得 到ActionBar actionBar.hide(); //隐藏ActionBar } }
评论
发表评论