Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get android to connect to the Internet (permission denied)

Here's my code:

URL url = new URL("http://www.bing.com/");
        URLConnection urlConnection = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
        in.close();

In the manifest, I have this:

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

It is outside the application tab, but inside the manifest tag.

And the error I'm getting is this:

java.net.SocketException: Permission denied (maybe missing INTERNET permission)

Really not sure why I'm getting this error when I have the internet permission in place. A bit stumped here!

Thanks!

like image 521
Mike Avatar asked Dec 22 '22 18:12

Mike


1 Answers

Shouldn't you have the following?

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

(Note the spelling modification between permission and uses-permission)

like image 97
KevinDTimm Avatar answered Dec 29 '22 12:12

KevinDTimm