Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't get my ip on android device although internet permission is set on manifest

I'm using eclipse + android SDK on ubuntu, and running a test activity server using sockets.

My Manifest has internet permission

<uses-permission android:name="INTERNET"/>

But when I look for my IP on the device using:

    // gets the ip address of your device
private String getLocalIpAddress() 
{
    try 
    {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) 
        {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) 
            {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); }
            }
        }
    } 
    catch (SocketException ex) 
    {
        Log.e("ServerActivity", ex.toString());
    }
    return null;
}

I get an exception on Logcat:

Java.net.SocketException: Permission denied

Tag: MyActivity, but i have internet permission on the manifest.

If i try to put the IP manually, when i use sockets, i get also the exception with TAG: System.err

Some ideas about the problem??

Thanks in advance.

like image 749
vgonisanz Avatar asked Feb 04 '26 08:02

vgonisanz


1 Answers

I think you must write the permission this way in the manifest xml:

<uses-permission android:name="android.permission.INTERNET"/>

instead of only "INTERNET". Try it just in case.

like image 124
Jav_Rock Avatar answered Feb 05 '26 21:02

Jav_Rock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!