更新时间:2023-11-26 10:49:28
var firebaseRef = new Firebase('http://INSTANCE.firebaseio.com');
firebaseRef.child('.info/connected').on('value', function(connectedSnap) {
if (connectedSnap.val() === true)
{
/* we're connected! */
}
else {
/* Give a custom Toast / Alert dialogue and exit the application */
}
});
您也可以添加此支票
public static boolean isNetworkAvailable(Context con) {
try {
ConnectivityManager cm = (ConnectivityManager) con
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
然后在活动/片段"中进行检查
Then check this in your Activity/Fragment
if (isNetworkAvailable)
{
//Do you task
}
else{
/*No internet so Give a custom Toast / Alert dialogue and exit the application */
}
请参阅链接以获取更多信息