• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps What is wrong with this code?

I have the following code:


public static String[] GetCategories(APPCLASS i) throws IOException
{
URL url = new URL("http://192.168.1.72/getcategories.php");
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();

Writer writer = new StringWriter();

char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
return writer.toString().split("" +
"");

}

http://192.168.1.72/getcategories.php is an address that does exist in a server on my network. My phone is connected to wifi, and when I go to that address in the browser it brings up the correct information. But when this code is ran in my application, it brings up an error: "Permission Denied (maybe missing INTERNET permission)" How can I fix this?

EDIT: I discovered that it fails at the line "InputStream is = conn.getInputStream();"
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones