Sourabh Saldi
Sourabh Saldi

Reputation: 3587

How to use phonegap plugins in our android project

I need to use sms plugin in my android application on phonegap

I've downloaded the required plugin also, I've changed all the instances of "phonegap" to "cordova" but I still get the error

    E/Web Console(2086): TypeError: Result of expression 
'window.plugins' [undefined] is not an object. at file:///android_asset/www/pluginexample.html:38

please give me link to any working project that uses plugin(any) so that I can know where I am getting this error

thanks!!!

Upvotes: 4

Views: 3625

Answers (4)

Harkedian
Harkedian

Reputation: 153

Do you mean how to use the plugin in your phonegap project or do you want to use phonegap plugin in your android (studio) project (If you are developing android apps with native langueage/java use android studio)?

The best way is from the plugin documentation. You can also check out this link : http://javatechig.com/cross-platform/phonegap/phonegap-sms-plugin-android

Upvotes: 0

Sandeep P
Sandeep P

Reputation: 4411

var MyPlugin = function () {};

MyPlugin.prototype.mFunctionName = function (action , successCallback, failureCallback, arrVal) {    
    return PhoneGap.exec(successCallback, failureCallback,  "ClassName", 'maction',arrVal );
};

PhoneGap.addConstructor(function() {
    PhoneGap.addPlugin("mObject", new MyPlugin());
});

your phonegap js will be in above form

you can call the above js like

window.plugins.mObject.mFunctionName('maction',function(success){},function(error){});

or

var mObj =  new MyPlugin();

    mObj.mFunctionName('maction',function(success){},function(error){});

Upvotes: 1

caiocpricci2
caiocpricci2

Reputation: 7788

Here you have a working sms plugin for phonegap. You can either use it as it is or rewrite for your specific needs!

SMS Plugin

Upvotes: 0

Related Questions