Android Get IP Address
Android application for fetching network IP address of the android device
Create new android project and add below code changes on MainActivity.java
Source SVN:Android IP Address Zipped Source :IPAddressDisplay.zip
Add network permission to AndroidManifest.xml
Create new android project and add below code changes on MainActivity.java
Source SVN:Android IP Address Zipped Source :IPAddressDisplay.zip
package com.javaorigin.ipdisplay; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { for (Enumerationen = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { TextView ipView= (TextView) findViewById(R.string.ip); ipView.setText(inetAddress.getHostAddress()); } } } } catch (Exception e) { Log.e("------------", e.toString()); } } }
Add network permission to AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
Comments
Post a Comment