Issue
I am using Fast Networking Library
in my project in which I have to get response of ConnectionQuality
but it always get ConnectionQuality.UNKNOWN
in response
. I am using Fast Networking Library.
Below is my code.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button btnNetworkQuality;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setIds();
setListner();
}
private void setIds() {
try {
btnNetworkQuality = (Button) findViewById(R.id.btnNetworkQuality);
} catch (Exception e) {
e.printStackTrace();
}
}
private void setListner() {
try {
btnNetworkQuality.setOnClickListener(this);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onClick(View view) {
try {
switch (view.getId()) {
case R.id.btnNetworkQuality:
checkBandwidth();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void checkBandwidth() {
Log.e("checkBandwidth() ", " ");
ConnectionQuality connectionQuality = AndroidNetworking.getCurrentConnectionQuality();
if(connectionQuality == ConnectionQuality.EXCELLENT) {
Log.e("Good quality "," ==> ");
// do something
} else if (connectionQuality == ConnectionQuality.POOR) {
Log.e("Poor quality "," ==> ");
} else if (connectionQuality == ConnectionQuality.UNKNOWN) {
Log.e("Unnown"," ==> ");
}
}
}
Solution
As the android framework does not provide a way to get the bandwidth of the connection, so I have implemented it a way that whenever you make the network request it calculate the data transfer and time taken. So, At the initial stage, you may get unknown. After some use, you will be able to get the correct connection quality in that session.
Answered By - Amit Shekhar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.