When my phone (Android) is not connected to the internet and I open the browser app, it pops up a dialog that says:
This application requires network access.
Enable mobile network or Wi-Fi to download data.
It then has two buttons - one for Settings and one for Cancel.
Pressing settings takes me directly to the "Wireless & networks" settings dialog.
I want to display a similar dialog from a phoneGap application. Can this be done?
Diagnostic plugin for PhoneGap may give your answer.
Download the plugin from the following link: Download Link
Than go through the following steps:
< script type="text/javascript" charset="utf-8" src="cordova-X.X.X.js">< /script >
< script type="text/javascript" charset="utf-8" src="diagnostic.js" > < /script >
Create a directory within your project called src/net/avantic/diagnosticPlugin and move Diagnostic.java into it.
In your res/xml/plugins.xml file add the following line:
< plugin name="Diagnostic" value="net.avantic.diagnosticPlugin.Diagnostic"/>
< uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
< uses-permission android:name="android.permission.BLUETOOTH" />
//Check whether Wifi is enable or not...
window.plugins.diagnostic.isWifiEnabled(wifiEnabledSuccessCallback, wifiEnabledErrorCallback);
//If function success callback result is 0 it will open the wifi settings dialog box...
function wifiEnabledSuccessCallback(result) {
if (!result){
alert("You must enable the Wi-Fi in device settings.");
window.plugins.diagnostic.switchToWifiSettings();
}
else{
alert("WiFi is ON!");
}
}
function wifiEnabledErrorCallback(error) {
console.log(error);
}
Hope the above solution will work for you..
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