Can not use cordova plugins inside ionic project


#1

I am new to Ionic and Cordova . I am trying to add a plugin

1.Created an ionic app using ionic start myproj

2.Added a cordova plugin using following command

cordova plugin add https://github.com/domaemon/org.apache.cordova.plugin.helloworld.git

3.Added navigator.helloworld.say();inside the ionic app.js as mentioned below

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)


    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);

    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleLightContent();
    }

    navigator.helloworld.say();
  });
})

when i am running the code through ionic serve…I am not getting the hello alert but i am getting the following error in the console as below

can not read property 'type' of undefined for the line navigator.helloworld.say();

Please let me know do i need to add any entries to any xml for mannual plugin addition or do i miss anything?


#2

seems to be broken a looooong time ago


#3

Cordova plugins do not work while developing in your browser, because each plugin accesses a specific API (such as camera, microphone, accelerometer) which is not available in your browser. Additionally, some plugins don’t work in the emulator, such as the Camera plugin, so development on your physical device is required.

While there are certain plugins that will work in the browser, and ways to get around the ones that don’t, by default this plugin will not work when testing from the browser. I tested this plugin in an android emulator and the alert worked. You can emulate it or run it directly on a device and see the alert.

Here is a good article on using plugins in the browser: http://www.raymondcamden.com/2014/09/24/Browser-as-a-platform-for-your-PhoneGapCordova-apps

There is also ngCordova, which wraps the cordova plugins in Angular wrappers:

ngCordova was built to help make app development faster and more efficient than ever before. It gives you simple AngularJS wrappers for the most popular Cordova and PhoneGap plugins available, where you can take a picture, scan a barcode, upload a file, turn on your flashlight, get your current location, and much more with just a few lines of code.

Please let me know if you have any questions or something I said didn’t make sense!


Check Ionic App new version
#4

@brandyshea Thanks for your reply. May I use the ionic view app instead of emulator? Does it work?


#5

So the Ionic View app is an Ionic app which hosts the www folder of your app using the InAppBrowser plugin. Therefore, the only plugins that will work for your app in Ionic View are those supported by the Ionic View app. A full list of supported plugins can be found here: http://docs.ionic.io/docs/view-usage

The safest way to test plugins is on a device. :smile:


#6

@brandyshea Great…!!

Now i can run the plugin in my real device and the emulator…!!! Really thank you for the great help…!!!