how to get ip address of pc in android emulator through code

前端 未结 2 1845
孤城傲影
孤城傲影 2021-01-13 19:59

i am using the code of this link How to get IP address of the device from code? but getting ip address different than from my machine....how can i get the ip address of my m

2条回答
  •  鱼传尺愫
    2021-01-13 20:19

    import the package java.net;

    and write the code,

    try {
    InetAddress thisIp =InetAddress.getLocalHost();
    System.out.println("IP:"+thisIp.getHostAddress());
    }
    catch(Exception e) {
    e.printStackTrace();
    }
    

提交回复
热议问题