[Q] Alawyas report network not available when using NewtorkInfo program

0 down vote favorite
share [g+] share [fb] share [tw]


I have wrote a program to check if the network is available or not. Here is my simple code:

Code:
public boolean isNetworkAvailable() { Context context = getApplicationContext(); ConnectivityManager connectivity=ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity == null) { boitealerte(this.getString(R.string.alert),"getSystemService rend null"); } else { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }

I run it on my Android phone, it always returns false but the network is available and I can make calls. Any suggestions>.

Show Accepted Answer

Guest Quick Reply (No URL, BBcode or HTML)

Last post by amparo57
3 hours ago
Last post by fkulas
4 hours ago
Last post by kertzmann.antonina
3 hours ago
Last post by terry.rene
2 hours ago
Last post by quentin.sanford
52 minutes ago