If the network is available or not, then I am having some problems while checking.
I use this code snippet inside a class AppPreferences to check the availability of a network.
Network return is available / available / public boolean network available () {connectionManager = (connectivity manager) reference .getSystemService (Context.CONNECTIVITY_SERVICE); Network available = connectionManager.getActiveNetworkInfo ()! = Null & amp; Amp; ConnectionManager.getActiveNetworkInfo () isConnected () .; Return network available; }Before each run, I set the theme as the following:
timer SchedulatEtex Factor (New TimerTask) (Public Zero Run) {appPreferences.setContext (GetBaseContext ()); If (appPreferences.isNetworkAvailable ()) {// works}}}, 0, UPDATE_INTERVAL; I know that this is not connected to the background thread because I have a responsive call on the same logic and still fails the check.
It seems that this primarily happens when it runs between cellular data connections and WiFi, or vice versa. This theme, which was started, though I think it is still despite updating it.
Do not anyone know what can be the problem here?
It seems that active network information will remain in place when service / activity / receiver starts . So if you start it on a network, and then disconnects from it later (i.e. 3G to WIFI and the 3G connection is disconnected) it will be built on the first active connection, Believe that the phone is offline, though it is not.
I think that the best solution is instead of the getApplicationContext user, because when you will not be compelled to start a special "work" Updates: It is related that if you run applications on Android (especially Nexus One), then check for a long period of time associated with WiFi that you make sure That sleeps on the screen when you do not sleep wifi. You will be able to set it up to the advanced option under the wireless network.
Comments
Post a Comment