Ashish Tamrakar
Ashish Tamrakar

Reputation: 820

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

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 machine on android emulator..

thanks in advance

Upvotes: 4

Views: 4726

Answers (2)

Aswin Anand
Aswin Anand

Reputation: 242

Check this out if you want to access host machine.

Another solution is to run this on shell

$ adb shell am start -a android.intent.action.WEB_SEARCH -e query "what is my ip"

it will display your system IP

Upvotes: 4

Neetesh
Neetesh

Reputation: 917

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();
}

Upvotes: 0

Related Questions