I have an application where it is necessary to monitor, and warn the user when he is without an internet connection available. To solve this, I created a BroadcastReceiver and show a toast when this happens. But I need to update this class so that instead of showing a toast, a TextView will be on the screen informing the user that it is offline. My idea is to put a layout with this TextView, over the current layout on the user screen until a connection is available, but the problem is that I can not make this view appear on any screen the user is on.
My Bradcast code is now:
public class Connectivity extends BroadcastReceiver {
Util util = new Util();
private ViewGroup mLinearLayout;
@Override
public void onReceive(Context context, Intent intent) {
if (!checkInternet(context)) {
util.showToast(context, "Sem conexão disponível com a internet.", 1);
}
}
boolean checkInternet(Context context) {
ServiceManager serviceManager = new ServiceManager(context);
if (serviceManager.isNetworkAvailable()) {
return true;
} else {
return false;
}
}
}
And the layout I'm trying to inflate, looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Sem conexão com internet disponível."
android:id="@+id/message"
android:layout_gravity="center_horizontal"
android:background="#e01b18"
android:gravity="center"
android:textColor="#FFF"
android:textSize="16dp" />
</RelativeLayout>
How do I get a warning from a class, regardless of which screen it is on?
In the end I need you to look like this: