cordova SMS plugin -- Issue

470 views
Skip to first unread message

Dinesh Guleria

unread,
Apr 28, 2015, 8:16:51 AM4/28/15
to phon...@googlegroups.com
Hi,

I am using cordova 3.6.3.
I am using following SMS plugin.


I have added plugin in following way :--
cordova plugin add com.rjfun.cordova.sms


My cordova app when loaded calls the following function doc_onload().

<body onload="doc_onload()">


Then this register the handler for "deviceready". When the device is ready this device ready function is called.

Now the problem inside the  initApp() handler is that SMS plugin check does not display any alert message.
I am able to get the alert --> "kk" . 

But in the following check  if (! SMS I did not get any display message.  Neither if nor else got satisfied.

Even     alert("end");   Does not get displayed  inside initApp() event handler.

Please suggest why it is failing ?

function initApp()
{
    alert
("initApp");
   
// attach Fastclick handler
   
FastClick.attach(document.body);


    alert
("kk");


   
if (! SMS )
   
{
        alert
( 'SMS plugin not ready' );
       
return;
   
}
   
else
   
{
        alert
( 'SMS plugin Ok ' );
   
}

    alert
("end");

   
//add SMS arrive listner handler
    document
.addEventListener("onSMSArrive", processSMS(), false);


}




//function doc_onload(page_type)
function doc_onload()
{


   
// Do some task
    alert
("doc_onload");


   
// add event handler for deviceready function
    document
.addEventListener("deviceready", initApp(), false);


}




Regards,
Dinesh

Dinesh Guleria

unread,
Apr 29, 2015, 7:38:51 AM4/29/15
to phon...@googlegroups.com
If i changed :--
if (typeof SMS === 'undefined' )

I use to get an alert output as :--
alert( 'SMS plugin not ready' );

Why SMS is not comming even after installing the plugin. ?

Dinesh Guleria

unread,
Apr 29, 2015, 8:06:38 AM4/29/15
to phon...@googlegroups.com
Means to say :--
I have added SMS plugin in following way :--
cordova plugin add com.rjfun.cordova.sms

But why object SMS is not defined in the cordova app ?

Please suggest ?

Kerri Shotts

unread,
Apr 29, 2015, 12:01:22 PM4/29/15
to phon...@googlegroups.com
You have an error in your code.

    document.addEventListener("deviceready", initApp(), false);

should be

    document.addEventListener("deviceready", initApp, false);

As it stands now, you're actually calling initApp /prior/ to `deviceready`. Sometimes it will work and sometimes not (depending on how everything else plays out wrt to loading scripts and such).

Dinesh Guleria

unread,
Apr 29, 2015, 2:14:36 PM4/29/15
to phon...@googlegroups.com
Do i have to add SMS.js file from author in my html file ?

http://plugins.cordova.io/#/package/com.rjfun.cordova.sms

This link have an index.html file example to use as refrence to be used as refrence to use this plugin, this file do not use SMS.js in html file .

Please suggest.

Kerri Shotts

unread,
Apr 29, 2015, 4:00:18 PM4/29/15
to phon...@googlegroups.com
No, you don't usually need to add a reference to the javascript as long as you've added the plugin via the CLI and include cordova.js.

You didn't indicate if removing the parens in my prior email helped or not.

Dinesh Guleria

unread,
Apr 30, 2015, 1:39:35 AM4/30/15
to phon...@googlegroups.com
@Kerri
>> You didn't indicate if removing the parens in my prior email helped or not.
Yes i am able to send the SMS now. I included "cordova.js" file & removed the bracket as you suggested & modified my code to if(typeof SMS === 'undefined').


I am able to send the SMS, but why the onSMSArrive .

handler is not called when my mobile phone running this cordova app receives an SMS ?
Following handler processSMS is not called ?

Please suggest what i have missed now ?



// process SMS
function processSMS(e)
{
   
var data = e.data;
    alert
("SMS received ");


    alert
(JSON.stringify(e, null, 10));

}




function initApp()
{
    alert
("initApp");
   
// attach Fastclick handler
   
FastClick.attach(document.body);



   
// check the SMS plugin
   
//if (! SMS )  --->>
   
if(typeof SMS === 'undefined')

   
{
        alert
( 'SMS plugin not ready' );
       
return;
   
}
   
else
   
{
        alert
( 'SMS plugin Ok ' );
   
}



    document
.addEventListener('onSMSArrive', processSMS, false);;
}

Dinesh Guleria

unread,
Apr 30, 2015, 6:41:13 AM4/30/15
to phon...@googlegroups.com
I added startwatch, this made it working, thanks for support :--


function startWatch() {
       
if(SMS) SMS.startWatch(function(){
        update
('watching', 'watching started');
       
}, function(){
        updateStatus
('failed to start watching');
       
});
       
}



Please suggest on these points from my side :---
What exactly happens to the cordova.js file when we add pluging at CLI ? 
So if we have to use any of the cordova plugin feature we have to add this cordova.js file right ?
Android programming is done in JAVA, so does cordova creates .jar files & JAVA object of our javascript code ? 

Raju Dasari

unread,
Aug 24, 2017, 8:27:50 PM8/24/17
to phonegap
i'm using Ionic 1 , and the 'startWatch' function is not getting triggered. I've added the plugin,and kept my code in deviceready event.

Please Help!

Kerri Shotts

unread,
Aug 24, 2017, 8:34:35 PM8/24/17
to phonegap
Don't resurrect old threads. Create a new post instead.
Reply all
Reply to author
Forward
0 new messages