android - get Connection Strength in Phonegap -


i working on phonegap application. want sync data application server, needs's connection strength.so need find out connection strength of connection.

there lots of documentation of internet find connection type using phonegap, can't find regarding connection strength

is there way find connection strength in phonegap, don't want use native platform code cause bw working on many platforms, there way find out connection(2g, 3g, 4g, wifi etc...) strength in phonegap????

there no standard way find out connection strength in android too, use javascript code speed of internet connection, there no issue platform android, ios or windows phone8 etc, no need develop separate plugin each platform.

i script :

    <script>             var downloadsize = 244736;             var imageaddr = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg" + "?n=" + math.random();             var starttime, endtime = 0;             var download = new image();              download.onload = function () {                 endtime = (new date()).gettime();                 showresults(starttime, endtime, imageaddr, downloadsize);             }              starttime = (new date()).gettime();             download.src = imageaddr;          });          function isconnected(){             var xhr = new xmlhttprequest();             var file = "http://api.androidhive.info/music/images/adele.png";             var r = math.round(math.random() * 10000);             xhr.open('head', file + "?subins=" + r, false);             try {                 xhr.send();                 if (xhr.status >= 200 && xhr.status < 304) {                     return true;                 } else {                     return false;                 }             } catch (e) {                 return false;             }            }          function showresults(starttime, endtime, imageaddr, downloadsize) {             if(isconnected){                 var duration = (endtime - starttime) / 1000; //math.round()                 var bitsloaded = downloadsize * 8;                 var speedbps = (bitsloaded / duration).tofixed(2);                 var speedkbps = (speedbps / 1024).tofixed(2);                 var finalspeed = (speedkbps/10);                  if(finalspeed < 40){                    // slow internet                  } else if(finalspeed >=40 && finalspeed < 80){                    // avg internet                  } else if(finalspeed >= 80){                   // fast internet                 }             }else{                 //no intenet             }             }    </script> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -