There are some questions in your question, I had android-studio
as a label but you explain that it is a hybrid app, if it is with Android Studio then it is native and to check the connectivity is this:
There are many examples, one of them ...
public class RevisarInternet{
private static final String TAG = RevisarInternet.class.getSimpleName();
public static boolean ConexionDisponible(Context context)
{
NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null)
{
Log.d(TAG,"No hay conexión de internet");
return false;
}
else
{
if(info.isConnected())
{
return true;
}
else
{
Log.d(TAG," Conexión a internet");
return true;
}
}
}
}
In your activity you want to show the Toast
:
if(RevisarInternet.ConexionDisponible(Activity.this))
{
// Muestras tu toast que si hay conexión
}
else
{
// Muestras tu toast que no hay conexión
}
You add this to your Manifest :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
Now, if it is a hybrid application (taking into account that it is Ionic because you do not specify what technology you use) you can test the network:
var myApp = angular.module('myapp', ['ionic'])
.run(function($ionicPlatform, $ionicPopup) {
$ionicPlatform.ready(function() {
if(window.Connection) {
if(navigator.connection.type == Connection.NONE) {
$ionicPopup.confirm({
title: "Internet Desconectado",
content: "No tienes internet."
})
.then(function(result) {
if(!result) {
ionic.Platform.exitApp();
}
});
}
}
});
});
Answers obtained from here and here.