Check for Internet Connection in the Android Application. Part 2.

Mobile Apps Development A-Z Guide.

Volodymyr Babenko
Pharos Production
3 min readFeb 4, 2019

--

Give us a message if you’re interested in Blockchain and FinTech software development or just say Hi at Pharos Production Inc.

Today it is difficult to imagine any application without access to the Internet. Background processes for updating information, sending and receiving messages — all this requires a connection. How to check the current status of the connection is shown in my previous article.

In the same article, I would like to talk about how to show current information to the user in real time.

In this article, I would like to talk about how to show current information to the user in real time. We need to create a fragment that will display a message on top of the contents of the current window and which will not take focus on itself.

Step 1.

Let’s create item_no_internet.xml file for our fragment:

item_no_internet.xml

Step 2.

In order for the message to display on the whole screen without indentation, create a theme.

strings.xml

Step 3.

And finally, let’s create our fragment, which will show the status of the connection.

InternetAlertDialog

Step 4.

In the previous article, we created the NetworkReceiver class and registered it in the Application Class. Now we will create an InetMonitor class, which will be responsible for registering the receiver and directly showing the custom Fragment created earlier.

InetMonitor

You can use this code in your android application using gradle:

Library usage.

To use the library, you need to add a dependency to the project as described above.

It is necessary to initiate the library in the class Application;

Next, you need to get an object that implements the InetMonitor.ConnectionListener interface

MainActivity

Thank you for reading!

--

--