I believe you are doing this in your main thread. Thats the reason its not working, you cant perform network operations in your main thread.
Try putting the code in AsyncTask or Thread.
Edit 1: As a quick fix try wrapping your "file checking code" like this:
new Thread() {
public void run() {
//your "file checking code" goes here like this
//write your results to log cat, since you cant do Toast from threads without handlers also...
try {
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
//HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
if( (con.getResponseCode() == HttpURLConnection.HTTP_OK) )
log.d("FILE_EXISTS", "true");
else
log.d("FILE_EXISTS", "false");
}
catch (Exception e) {
e.printStackTrace();
log.d("FILE_EXISTS", "false");;
}
}
}.start();