I am using Xamarin.Android and wrote the following code:
public TextView text;
text = FindViewById<TextView>(Resource.Id.viewIP);
foreach (IPAddress adress in Dns.GetHostAddresses(Dns.GetHostName()))
{
text.Text = "IP Adress: " + adress;
}
However, when I open the application it shuts down immediately. Am I using the correct way of getting the IP address' of the device?
For me this worked in PCL Xamarin:
All the answers I've seen to this question have only gotten the internal IP address of my device while on my home network (198.162.#.#). So I took a slightly different approach, and ask the internet more directly. ipify.org has a nice and simple endpoint for getting your IP address, that can be executed in your shared code. For example...
Where "IpResult" is a POCO with a single string property named "Ip" (that you need to create, in addition to this code.)
From the Xamarin forums
added to mainifest:
for get local ip:
See this answer : https://stackoverflow.com/a/6803109/4349342