i dont know what happen but my code cannot get response / status code and always get blank exception.
if (!GetS1.isEmpty() || !GetS1.equals("")) {
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
url = new URL(GetS1);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(2000);
urlConnection.setReadTimeout(2000);
urlConnection.connect();
final int responseCode = urlConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
ButtonS1.setEnabled(true);
ButtonS1.setText("ACTIVE");
} else if (responseCode == HttpURLConnection.HTTP_FORBIDDEN) {
ButtonS1.setText("BLOCKED");
} else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
ButtonS1.setText("DOWN");
} else {
ButtonS1.setText("UNKNOWN / BROKEN");
}
} catch (Exception e) {
Toast.makeText(Act_Details.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
am i missing something? i am already set permission using internet in manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />