Checking Quality of Internet Connection

What is the best practice of insuring an android devices internet connection is sound enough for file transfers and AJAX calls?

Thanks for any input.

This looks promising, but I can’t get it to run in NAB APPStudio.
Granted I mostly a Visual Basic guy. I put this between Javascript tags -
Uncaught SyntaxError: Unexpected identifier

public boolean isOnline() {
    Runtime runtime = Runtime.getRuntime();
    try {
        Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
        int     exitValue = ipProcess.waitFor();
        return (exitValue == 0);
    }
    catch (IOException e)          { e.printStackTrace(); }
    catch (InterruptedException e) { e.printStackTrace(); }

    return false;
}

I don’t believe there’s a reliable way to know that on the front end. As a result, handling an Ajax error should the connection fail is an important piece of code to include in your app.

In JavaScript, there are a couple of things you can check to give you an idea of the state of the network connection, but they don’t always ‘tell the truth’, so to speak.
navigator.onLine
navigator.connection.downlink (Chrome only)

Google them for more info.

Your code example above doesn’t appear to be JavaScript, which is probably why it’s not working in AppStudio.

Kind regards,
Doug

The best way is to pull a file from your server and time it. Depending on testing you can figure what is Good, Marginal and Poor connections.

Function GetBandwidth(openForm)
  WaitCursor(True)
  gSignalStrength = ""
  gGetBandWidth = ""
  gt0 = 0
  gt1 = 0
gToForm = openForm
'console.log(gToForm)
txtPassword ="password=password"
gt0 = performance.now()
reqInternet=Ajax("http://yourServer.com/GetBandwidth.php","POST",txtPassword, AjaxBandwidthSuccess, AjaxBandwidthFail)
End Function

Function AjaxBandwidthSuccess()
gt1 = performance.now()
  If  (reqInternet.status = 200) Then 'success
 gGetBandWidth = "SUCCESS"
 varSpeed = Round(gt1-gt0, 1)
If varSpeed >= 1 And varSpeed <= 400 Then gSignalStrength = "GOOD"
If varSpeed > 400 And varSpeed <=800 Then gSignalStrength = "MARGINAL"
If varSpeed > 800 Then gSignalStrength = "POOR"
Select Case gSignalStrength
    Case "GOOD"
    MsgBox("DEVICE CONNECTED TO SERVER: " & vbCRLF & "SIGNAL STRENGTH IS " & gSignalStrength,0,gGetBandWidth & " : " & CStr(varSpeed))
    Case "MARGINAL" 
    MsgBox("DEVICE CONNECTED TO SERVER: " & vbCRLF & "SIGNAL STRENGTH IS " & gSignalStrength,0,gGetBandWidth & " : " & CStr(varSpeed))
    Case "POOR"
    MsgBox("DEVICE CONNECTED TO SERVER: " & vbCRLF & "SIGNAL STRENGTH IS " & gSignalStrength,0,gGetBandWidth & " : " & CStr(varSpeed))
    gGetBandWidth = "FAILED"
    Case Else
        gGetBandWidth = "FAILED"
    MsgBox("Your DEVICE CANNOT REACH HQ" & vbCRLF & "Check Connection and Retry",0,gGetBandWidth)
    End Select
  Else
    gGetBandWidth = "FAILED"
    MsgBox("Your DEVICE CANNOT REACH HQ" & vbCRLF & "Check Connection and Retry",0,gGetBandWidth)
 
 End If
'console.log("Call took "  & (gt1 - gt0) & " milliseconds." & vbCRLF & gSignalStrength)
If gGetBandWidth = "SUCCESS" Then
  ChangeForm(window[gToForm])
End If
WaitCursor(False)
End Function

Function AjaxBandwidthFail()
gGetBandWidth = "FAILED"
MsgBox("Your DEVICE CANNOT REACH HQ" & vbCRLF & "Check Connection and Retry",0,gGetBandWidth)
WaitCursor(False)
End Function

Hi.

you can use phonegap functionality to determine the Internet connection type that you have… 2g, 3g, 4g and wifi.

perhaps you can restrict the file transfer only with 4g or wifi