[TIMOB-6503] MobileWeb: Ti.Network.networkType always returns -1 with networkTypeName as UNKNOWN
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Low |
| Status | Closed |
| Resolution | Invalid |
| Resolution Date | 2012-02-13T16:46:35.000+0000 |
| Affected Version/s | Release 1.8.0.1 |
| Fix Version/s | n/a |
| Components | MobileWeb |
| Labels | n/a |
| Reporter | Anthony Decena |
| Assignee | Chris Barber |
| Created | 2011-12-07T12:01:59.000+0000 |
| Updated | 2014-01-28T23:57:35.000+0000 |
Description
Regardless of browser or device, the networkType always returns -1 and the networkTypeName returns UNKNOWN.
Ti.API.info('type:' + Titanium.Network.networkType);
Ti.API.info('online:' + Titanium.Network.online);
Ti.API.info('name:'+Titanium.Network.networkTypeName);
The reason it's -1 is because that's the value of the constant Ti.Network.NETWORK_UNKNOWN. Android 2.2+ is the only web browser that reports the connectivity information. For all other browsers, there's no way to accurately detect the network type. You could do a speed test downloading an image to best guess, but it's unreliable. To implement this for Android 2.2+, implement checks for navigator.connection.type. Refer to http://davidbcalhoun.com/2010/using-navigator-connection-android and http://stackoverflow.com/questions/4459029/is-there-a-way-to-detect-if-a-user-is-on-a-wifi-connection-with-php-or-javascrip.
This actually already returns correctly for the Android web browser. Returning type = 3 and name = MOBILE for any Android 2.2+ browser.
This is a non-issue and works as expected.