2

I ever made a sms filter in android, now i wanna use phonegap. what API can i use to read the number and content of the sms with PhoneGap when incoming sms?

1 Answer 1

1

Below is a link to a phonegap plugin that allows you to receive incoming SMS. You have the possibility to stop the message broadcasting and, thus, avoid the incoming message native popup.

All you have to do is follow the following steps to setup your SMS Receiver.

Adding the plugin to your project

(Make sure you are using Phonegap > 2.0) 1 .Move SmsInboxPlugin.js to your project's www folder and include a reference to it in your html files. 2. Add the java files from src to your project's src hierarchy 3. Reference the plugin in your res/config.xml file 4. Ensure that your manifest contains the necessary permissions to send SMS messages:

Include the following script in your html file.

var smsInboxPlugin = cordova.require('cordova/plugin/smsinboxplugin');

smsInboxPlugin.isSupported ((function(supported) {
    if(supported) 
      alert("SMS supported !");
    else
      alert("SMS not supported");
  }), function() {
    alert("Error while checking the SMS support");
  });




smsInboxPlugin.startReception (function(msg) {
       alert(msg);
  }, function() {
      alert("Error while receiving messages");
  });

To stop reception use this script

smsInboxPlugin.stopReception (function() {
    alert("Correctly stopped");
  }, function() {
    alert("Error while stopping the SMS receiver");
  });

The plugin can be found at https://github.com/Pyo25/Phonegap-SMS-reception-plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.