Just installed cordova plugin on my new project. cordova plugin add cordova.plugins.diagnostic
I successfully added it.
Then I test it first using this basic code:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
function log(msg) {
console.log(msg);
document.body.innerHTML += '<p>' + msg + '</p><br><br><br><br>';
}
function onReady() {
log("deviceready");
try {
cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
log("Location enabled: " + enabled);
}, function(error) {
log("A plugin error occurred: " + error);
});
} catch (e) {
log("An exception occurred: " + e.message);
}
}
document.addEventListener("deviceready", onReady, false);
</script>
After running the code on browser and on my andriod phone using phonegap mobile developer. I got an error.
An exception occurred: Cannot read property 'diagnostic' of undefined
. I tried building apk of the app, the same is the error. What could be the problem?
Here are my plugin list:
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-inappbrowser 3.2.0 "InAppBrowser"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-request-location-accuracy 2.3.0 "Request Location Accuracy"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova.plugins.diagnostic 5.0.1 "Diagnostic"
And my config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.test.location" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Test</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<preference name="phonegap-version" value="cli-6.4.0" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova-plugin-dialogs" spec="~2.0.2" />
<plugin name="cordova-plugin-geolocation" spec="~4.0.2" />
<plugin name="cordova-plugin-request-location-accuracy" spec="~2.3.0" />
<plugin name="cordova-plugin-inappbrowser" spec="~3.2.0" />
<plugin name="cordova-plugin-network-information" spec="~2.0.2" />
<plugin name="cordova.plugins.diagnostic"/>
</widget>
Any help is appreciated. Thank you.
After running the code on browser and on my andriod phone using phonegap mobile developer
As documented, the plugin only supports native Android & iOS environments so will not work with the browser platform or phonegap developer app (which is pre-compiled).
To use this plugin you will need to build and run the app on the native mobile platform:
cordova platform add android && cordova run android
cordova platform add ios && cordova run ios