I am creating a hybrid application by using android and offline html5 pages in android asset. navigator.online is not working in Android Webview.
Please help
If anyone is still searching for this one. The solution for me was to register a broadcast receiver in my activity to detect connection change.
@Override
protected void onPause() {
super.onPause();
if (connectivityChangeReceiver!=null) unregisterReceiver(connectivityChangeReceiver);
}
@Override
protected void onResume()
{
super.onResume();
IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
registerReceiver(connectivityChangeReceiver,intentFilter);
}
private BroadcastReceiver connectivityChangeReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent)
{
mWebView.setNetworkAvailable(isNetworkAvailable(context));
}
};
Make sure that you provide below permissions in the AndroidMenifest.xml
file:
<uses-permission android:name="android.permission.INTERNET />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
you might want to add the following line of code for your events
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
make sure you check the values in the functions function onOnline(){}
& function onOffline(){}
Are you sure you are not mistaking the spelling?
it should be navigator.onLine (camelCase)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With