facebookarchive / network-connection-class

Listen to current network traffic in the app and categorize the quality of the network.
Other
3.18k stars 515 forks source link

ConnectionQuality is always unknown #22

Open Dgotlieb opened 8 years ago

Dgotlieb commented 8 years ago

I tried doing the following:

`ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
            switch (cq) {
                case EXCELLENT: //Bandwidth over 2000 kbps.
                    Toast.makeText(MainActivity.this, "EXCELLENT", Toast.LENGTH_SHORT).show();
                    break;
                case GOOD: //Bandwidth between 550 and 2000 kbps.
                    Toast.makeText(MainActivity.this, "GOOD", Toast.LENGTH_SHORT).show();
                    break;
                case MODERATE: //Bandwidth between 150 and 550 kbps.
                    Toast.makeText(MainActivity.this, "MODERATE", Toast.LENGTH_SHORT).show();
                    break;
                case POOR: //Bandwidth under 150 kbps.
                    Toast.makeText(MainActivity.this, "POOR", Toast.LENGTH_SHORT).show();
                    break;
                case UNKNOWN: //unknown
                    Toast.makeText(MainActivity.this, "UNKNOWN", Toast.LENGTH_SHORT).show();
                   break;

              }`

And keep getting Unknown.

sreejithr commented 8 years ago

@Dgotlieb You probably haven't sampled any data. Try putting DeviceBandwidthSampler.getInstance().startSampling() and DeviceBandwidthSampler.getInstance().stopSampling() between some bandwidth consuming section.

tosulc commented 8 years ago

@sreejithr Is it mandatory to implement ConnectionClassStateChangeListener and have this initialization ConnectionClassManager.getInstance().register(this); before starting and stopping sampling?

Dgotlieb commented 8 years ago

Tried DeviceBandwidthSampler.getInstance().startSampling() still not working.. Thanks you

tosulc commented 8 years ago

@SeyelentEco I see that you've been working the most on this lib. More info? :)

sreejithr commented 8 years ago

@TOMKHAN Has any traffic happened between your app start and when you check ConnectionClassManager.getInstance().getCurrentBandwidthQuality()?

tosulc commented 8 years ago

@sreejithr Yep. I'm starting sampling, then making network request and then stopping it. Still have no idea if "ConnectionClassManager.getInstance().register(this);" call is needed.

WxSmile commented 7 years ago

@Dgotlieb Did you solve it?

pranay18 commented 7 years ago

I am getting the same problem. If I increase the size of data to be downloaded between the start sampling and stop sampling calls, everything works fine. But if the data being downloaded is small, I always get UNKNOWN network. Has anyone found a workaround for this issue? @Dgotlieb @sreejithr @TOMKHAN @zpao @WxSmile