Phonegap (online build) app - no internet connection and network status

点点圈 提交于 2019-11-29 06:42:53

Add the whitelist plugin

<gap:plugin name="cordova-plugin-whitelist" source="npm" />

You might need to add this meta tag on the head

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src *  'unsafe-inline'; script-src *  'unsafe-inline'; media-src *">

And add this two lines to the config.xml

<allow-navigation href="http://*/*" />
<allow-intent href="https://*/*" />

For checking internet connection I use this function:

function checkConnection(){
            var networkState = navigator.connection.type;
            if(Connection.NONE==networkState)
                return "<p>No connection</p>";
}

For being able yo use it you have to add the network state plugin this way:

cordova plugin add cordova-plugin-network-information

Your AndoidManifest file should include this two lines:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!