Skip to content

Commit

Permalink
Fix read timed out google
Browse files Browse the repository at this point in the history
Fix read timed out google
  • Loading branch information
oaliaga committed Jan 31, 2024
1 parent b647796 commit ac89f63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {

targetSdkVersion 33

versionCode 323
versionName '2.5.1'
versionCode 324
versionName '2.5.2'

multiDexEnabled true

Expand Down
34 changes: 1 addition & 33 deletions app/src/main/java/com/prey/net/UtilConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,39 +557,7 @@ public static int uploadFile(PreyConfig preyConfig,String page, File file,long t
* @return available
*/
public static boolean isInternetAvailable(Context context) {
try {
boolean isTimeNextPing = PreyConfig.getPreyConfig(context).isTimeNextPing();
if (isTimeNextPing) {
return true;
}
boolean isInternetAvailable = false;
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
try {
HttpURLConnection urlGoogle = (HttpURLConnection) (new URL("http://www.google.com").openConnection());
urlGoogle.setRequestProperty("User-Agent", "Test");
urlGoogle.setRequestProperty("Connection", "close");
urlGoogle.setConnectTimeout(500); //choose your own timeframe
urlGoogle.setReadTimeout(500); //choose your own timeframe
urlGoogle.connect();
isInternetAvailable = (urlGoogle.getResponseCode() == HttpsURLConnection.HTTP_OK);
} catch (IOException e) {
PreyLogger.e(String.format("isInternetAvailable error:%s", e.getMessage()), e);
isInternetAvailable = false; //connectivity exists, but no internet.
}
}
}
}
}
return isInternetAvailable;
} catch (Exception e) {
PreyLogger.e(String.format("isInternetAvailable error:%s", e.getMessage()), e);
}
return false;
return true;
}

private static boolean isInternet() {
Expand Down

0 comments on commit ac89f63

Please sign in to comment.