1. 添加 service

在 activity 后面, application 添加, service 的类名标示在属性 name 中, 路径为从 src 下的包名到类名, 若只有一个包, 可以直接用 (.类名) 标示

2. java 获取本机地址

  先是反例

  

//get localhost ip address        InetAddress addr;        try {            addr = InetAddress.getLocalHost();            String ip = addr.getHostAddress().toString();            System.out.println("Listening on "+ip+":"+listener.getPort());        } catch (UnknownHostException e1) {            // TODO Auto-generated catch block            e1.printStackTrace();        }

  再是正解

Enumeration<NetworkInterface> ip;        try {            ip = NetworkInterface.getNetworkInterfaces();            while(ip.hasMoreElements()) {                NetworkInterface iface = ip.nextElement();                 if (iface.isLoopback() || !iface.isUp())                        continue;                                 Enumeration<InetAddress> addresses = iface.getInetAddresses();                    while(addresses.hasMoreElements()) {                        InetAddress addr = addresses.nextElement();                        String desiredip = addr.getHostAddress();                        System.out.println(iface.getDisplayName() + " " + desiredip);                    }            }        } catch (SocketException e1) {            // TODO Auto-generated catch block            e1.printStackTrace();        }        

直接查询 IPconfig 就好了, 动态的话, 是有些 tricky, 上面的正解也并不是很有效

更多相关文章

  1. RemoteViews用法一:widget简单用法
  2. MonkeyRunner进坑——errors importing other modules
  3. Android添加多语言
  4. android GUI反编译工具 APKDecoderV0.9
  5. 5.3 ListView的HeaderView
  6. android 设置程序安装位置
  7. Android(安卓)Studio(2.3.3)配置Kotlin笔记
  8. Android(安卓)OpenCV使用1_导入OpenCV并依赖该项目
  9. eclipse开发android

随机推荐

  1. android studio 3.x 以上版本的Native JN
  2. 无Mac机IOS开发环境搭建手记
  3. android实时滤镜的效率问题
  4. android开发基础(Android Application Fun
  5. Android(安卓)WebView加载Chromium动态库
  6. Android Wear之android穿戴式设备应用开
  7. android中获取手机相机和相册可以传多张
  8. 什么是Android(安卓)系统。
  9. Android(安卓)Context 到底是什么?
  10. Android之第三方库“scnu-jwc-sdk-1.0.0