Check GPS state (on/off) in ionic/cordova
10:05 AM
Fist you've to install the plugin https://github.com/dpa99c/cordova-diagnostic-plugin then simply execute this code after platform ready :
Check GPS state (on/off) in ionic/cordova
Check GPS state (on/off) in ionic/cordova
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
console.log("Location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
console.error("The following error occurred: "+error);
});
Check WiFi is enable or not?
cordova.plugins.diagnostic.isWifiEnabled(function(enabled){
console.log("WiFi is " + (enabled ? "enabled" : "disabled"));
}, function(error){
console.error("The following error occurred: "+error);
});
Check device has a camera AND the application is authorized to use it. or not?
cordova.plugins.diagnostic.isCameraEnabled(function(exists){
console.log("Device " + (exists ? "does" : "does not") + " have a camera");
}, function(error){
console.error("The following error occurred: "+error);
});
Enables/disables WiFi on the device
cordova.plugins.diagnostic.setWifiState(function(){
console.log("Wifi was enabled");
}, function(error){
console.error("The following error occurred: "+error);
},
true);
Checks the device has Bluetooth capabilities and if it has then Bluetooth is on or off?
cordova.plugins.diagnostic.isBluetoothEnabled(function(enabled){
console.log("Bluetooth is " + (enabled ? "enabled" : "disabled"));
}, function(error){
console.error("The following error occurred: "+error);
});
Enables/disables Bluetooth on the device
cordova.plugins.diagnostic.setBluetoothState(function(){
console.log("Bluetooth was enabled");
}, function(error){
console.error("The following error occurred: "+error);
},
true);
0 comments