Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6366] Titanium.Network.addEventListener ignores Mobile Data on Android Devices

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDone
Resolution Date2019-11-04T19:03:05.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, api
Reportercstefaniga
AssigneeShak Hossain
Created2019-09-12T13:59:51.000+0000
Updated2019-11-04T19:03:06.000+0000

Description

Reproduces also with SDK 8.1.0 GA On Android Devices (tested on Samsung) the Titanium.Network.addEventListener responds only to WIFI changes and ignores completely the MobileData. So for example if the MobileData is turned on and the Wifi is connected. When closing the WIFI the Titanium.Network.online will return false even though the phone has access to internet via MobileData. If you turn On/Off the mobile data the listener does not respond at all.

Attachments

FileDateSize
console-log.rtf2019-09-17T06:34:52.000+000038384

Comments

  1. cstefaniga 2019-09-13

    just add this code snippet to an app.js Titanium.Network.addEventListener('change', function(e){ Ti.API.error('Network system state: ' + (Titanium.Network.online ? 'ONLINE' : 'OFFLINE')); Ti.API.error('Network event state: ' + (e.online ? 'ONLINE' : 'OFFLINE') + ' on ' + e.networkTypeName); });
  2. cstefaniga 2019-09-16

    Hi, Yes it reproduced with 8.1.1 GA
  3. Nazmus Salahin 2019-09-17

    Hello [~Claudiu Stefaniga]! We have tested this issue using the provided sample code on Samsung galaxy A7 (2018) android 9. it's working as expected on our end. *Test Environment:*
       Appcelerator Command-Line Interface, version 7.0.12
       Operating System
         Name                        = Mac OS X
         Version                     = 10.13.6
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8589934592
       Node.js
         Node.js Version             = 8.9.4
         npm Version                 = 6.10.0
       Titanium CLI
         CLI Version                 = 5.1.1
       Titanium SDK
         SDK Version                 = 8.1.1.GA
         Target Platform             = android
       
    *Code:* *app.js*
       var win = Ti.UI.createWindow({
       	backgroundColor : '#fff'
       });
        
       Titanium.Network.addEventListener('change', function(e)
       
       { Ti.API.error('Network system state: ' + (Titanium.Network.online ? 'ONLINE' : 'OFFLINE')); Ti.API.error('Network event state: ' + (e.online ? 'ONLINE' : 'OFFLINE') + ' on ' + e.networkTypeName); }
       );
        
       win.open();
       
    *Test steps:* 1. Create a new classic project. 2. Copy the code and paste in app.js. 3. Run the project on android device. 4. After running the project, MobileData is turned on and the Wifi is connected. 5. When closing the WIFI the listener access to the internet via MobileData. 6. If you turn On/Off the mobile data the listener goes offline and online as well. *Test Output:* Please check the attachment section.
  4. cstefaniga 2019-09-17

    on Samsung Galaxy S7, Android 7.1 API 25 it does not work. could you please attach the app.js also ... maybe I'm doing something wrong
  5. Nazmus Salahin 2019-09-17

    Hello [~Claudiu Stefaniga]! *app.js*
       var win = Ti.UI.createWindow({
       	backgroundColor : '#fff'
       });
        
       Titanium.Network.addEventListener('change', function(e)
       
       { Ti.API.error('Network system state: ' + (Titanium.Network.online ? 'ONLINE' : 'OFFLINE')); Ti.API.error('Network event state: ' + (e.online ? 'ONLINE' : 'OFFLINE') + ' on ' + e.networkTypeName); }
       );
        
       win.open();
       
    Thanks
  6. cstefaniga 2019-09-18

    OK, I think I got it. when we turn of the WIFI and the android goes to Mobile data we receive actually 2 event [ERROR] : Network system state: OFFLINE [ERROR] : Network event state: OFFLINE on NONE and very soon after we receive [ERROR] : Network system state: ONLINE [ERROR] : Network event state: ONLINE on MOBILE My problem was that in my genymotion simulator I did not receive the second event which put the network state to online on mobile. (if I use the emulators provided by Android Studio -> the events are there) And when testing on devices I actually checked the functionality (which throws and event when network changes and then consumes it in another part of the app, but that part of the app has a _debounce -> so it will ignore for 3 seconds other Network changes) thanks for the support
  7. Sharif AbuDarda 2019-11-04

    Hello [~Claudiu Stefaniga], the reason you don't get the second event logged in the Genymotion emulator is that the emulators always use WIFI for connectivity from the PC. Thanks.

JSON Source