1、Android 获取本机Mac 地址方法:



需要在AndroidManifest.xml文件中添加权限:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

public String getLocalMacAddress() {WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);WifiInfo info = wifi.getConnectionInfo();return info.getMacAddress();}


2、Android 获取本机IP地址方法:
public String getLocalIpAddress() {try {for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {NetworkInterface intf = en.nextElement();for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {InetAddress inetAddress = enumIpAddr.nextElement();if (!inetAddress.isLoopbackAddress()) {return inetAddress.getHostAddress().toString();}}}} catch (SocketException ex) {Log.e("WifiPreference IpAddress", ex.toString());}return null;}


更多相关文章

  1. Android 远程链接 daemon not running 解决方法
  2. android > Android实现计时与倒计时的几种方法
  3. Android 根据坐标获取地址
  4. Android 复习笔记之图解TextView类及其XML相关属性和方法
  5. android.support library找不到的解决方法
  6. android 调用 react-native方法
  7. Eclipse build Android时不生成apk问题解决方法
  8. Android的线程使用来更新UI----View的几种更新方法(Thread、Hand

随机推荐

  1. android 开发小记
  2. Android通过WebView调用 JS 代码
  3. android屏幕常亮
  4. 禁止Android的StatusBar下拉
  5. android 删除文件,打开指定的文件类型
  6. Android(安卓)学习笔记 Contacts (三)Conta
  7. cxf android客户端简单访问
  8. Android下使用Properties文件保存程序设
  9. android 权限
  10. android中使用local_manifest.xml添加软