How to check my internet access on Android? -


What exactly do I have to do when there is no connection to the user, then I have to show some dialogue that some of his relation is not .

I tried to put it on my main activity but still did not work.

  Public Boolean is online () {Connectivity Manager Semi = (Connectivity Manager) getSystemService (context.CONNECTIVITY_SERVICE); Return cm.getActiveNetworkInfo (). IsConnectedOrConnecting (); }   

I have also used this but it also does not work:

  Public class connection change expands receiver broadcasts receiver {@ Public Recovery Referenced on Revive (Reference Reference, Intent of Intent) (Connectivity Manager Connectivity Manager = (Connectivity Manager) context.getSystemService (Reference. CONNECTIVITY_SERVICE); NetworkInfo ActiveNetOfO = ConnectivityManager.ctactivnet Info (); NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo (Connectivity Manager. TYPE_MOBILE); if (activeNetInfo! = Null) {Toast.makeText (reference, "Active Network type:" + ActiveNet.TetPepName (), Toast .LENGTH_SHORT) ();} If (mobNetInfo! = Null) {Toast.makeText (reference, "Mobile network type:" + mobNetInfo.getTypeName (), Toast .LENGTH_SHORT) Show ();}}}   

I added it to my manifest:

  Use of Android - permission: name = "android.permission.ACCESS_NETWORK_STATE" />   

This link might help you a bit more:

If you need access to more activities, you can be in your activity before or after the composite communications manager code, you can declare the client a stable in the singleton instance and it will be there from You can call in the described form

You can store your application in the manifest Dkast receiver must be registered:

  & lt; Receiver Android: Enabled = "True" Android: name = "com.project.mobile.controller.comm. Connectivity Receiver" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.net.conn.CONNECTIVITY_CHANGE" /> & Lt; / Intent-Filter & gt; & Lt; / Receiver & gt;   

Enjoy

Comments