Reputation: 24474
For multicast purposes, I'm looking for a simple way to detect when the IP of an Android device changes. How can I go about doing so?
More specifically, I'm looking to detect:
Upvotes: 6
Views: 8379
Reputation: 7102
You can do this with the ConnectivityManager:
You can use this to query the current connection state:
ConnectivityManager connMananger = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connMananger.getActiveNetworkInfo();
The current IP address of network interfaces can be acquired with NetworkInterface.getNetworkInterfaces()
And you can receive automatic notification of when the connection state changes via the CONNECTIVITY_ACTION broadcast
Upvotes: 6