0

I want to get the ip address of my android phone connected to 3G programatically.I jus used simple way of getting Ip address as below

InetAddress address=InetAddress.getLocalHost();
Log.d("TAG","IPAddress::"+address.getHostAddress());

Its always returning loopback address(127.0.0.1).How to get the public address?

androidGuy
  • 5,553
  • 12
  • 39
  • 56
  • It seems that phones do not get a public IP address when only connected over the phone network. If you connect to a WiFi network it will get a public IP address, and keep that address even when WiFi is turned off. – Some programmer dude Feb 13 '12 at 08:07

3 Answers3

0

Just keep in mind that you can't really use that IP when on 3G for sending something to the phone, since the infrastructure is not transparent. For pushing messages to the phone, use Google Cloud Messaging

http://developer.android.com/google/gcm/index.html

Aleksandar Stojadinovic
  • 4,851
  • 1
  • 34
  • 56
0

I think there is no clear API for this (this feature is not implemented still).

But there are other possible ways to get current Ip information. For instance, look here.

Yury
  • 20,618
  • 7
  • 58
  • 86
0

There is no API for this yet. An easy way to do this would be to access a web page that reports your public IP and then parse the page for the IP address.

You can do a simple Google search for "ip" and it will tell you your public IP address:

https://www.google.com/search?q=ip

Jake Wilson
  • 88,616
  • 93
  • 252
  • 370