Giter Club home page Giter Club logo

cordova-plugin-sms's Introduction

cordova-plugin-sms

Plugin to operate SMS, send / list / intercept / delete / restore.

How to Use?

Use the plugin with Cordova CLI (v5.x or above):

cordova plugin add cordova-plugin-sms

When use with PhoneGap Build, write following line in your config.xml:

<gap:plugin name="cordova-plugin-sms" source="npm" />

API Overview

Methods

sendSMS(address(s), text, successCallback, failureCallback);
listSMS(filter, successCallback, failureCallback);
deleteSMS(filter, successCallback, failureCallback);

startWatch(successCallback, failureCallback);
stopWatch(successCallback, failureCallback);

enableIntercept(on_off, successCallback, failureCallback);
restoreSMS(msg_or_msgs, successCallback, failureCallback);

setOptions(options, successCallback, failureCallback);

Events

'onSMSArrive'

Quick Start

	# create a demo project
    cordova create test1 com.rjfun.test1 Test1
    cd test1
    cordova platform add android
    
    # now add plugin
    cordova plugin add cordova-plugin-sms
    
    # copy the demo file
    rm -r www/*; cp plugins/cordova-plugin-sms/test/* www/;
    
	# now build and run the demo in your device or emulator
    cordova prepare; 
    cordova run android; 
    
    # or import into Xcode / eclipse

Documentation

Check the API Reference

Check the Example Code in test/index.html.

Demo

ScreenShot

Credits

The plugin is created and maintained by Raymond Xie.

You can use it for FREE, it works in trial mode by default.

A valid license is required to get email support, or use it in commercial product.

See Also

More Cordova/PhoneGap plugins by Raymond Xie, visit http://rjfun.github.io/.

Cordova/PhoneGap plugins for the world leading Mobile Ad services:

Project outsourcing and consulting service is also available. Please contact us if you have the business needs.

cordova-plugin-sms's People

Contributors

floatinghotpot avatar k88hudson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-sms's Issues

Old devices

@floatinghotpot have you tried the example in android 4.0.3 or under? I think there is a problem on those.

I tried in an HTC One S (WebKit/534.30), and see no error while the app it's bootstrapping, even I can see the message that it's on "watching" mode, but when an SMS arrive there is no confirmation, it's like no message had arrived at all.

deleteSMS doesn't work

SMS.deleteSMS({box: '', address: gate_address}, function(n) {
alert(n + ' sms messages deleted');
}, function(err){
alert('error delete sms: ' + err);
});

showing "X sms messages deleted" and nothing ((

Android 4.4.2

Permission Denial

permissions error on android 6.0.1

error list sms: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content ://sms/inbox requires android.permission.READ_SMS , or grantUriPermission()

restoreSMS issue - not saving

I am trying to restore backed up SMS messages, I have created a simple function to test my logic - i do get a success callback but nothing is being saved to the phone (SAMSUNG S4).

Any direction would be much appreciated.

I have tried with two variations of the msgs as objects, one with all fields and the other with just the address and body. Objects passed are called objSMS or objSMSA.

**** see function below ****

function saveSMS() {

    var textSMS = '[{ "_id":"30","address":"0813132204","app_id":"0","body":"Boo..who goes there bbb","date":"1477483120209","date_sent":"0","deletable":"0","error_code":"0","hidden":"0","locked":"0","msg_id":"0","pri":"0","read":"1","reserved":"0","roam_pending":"0","safe_message":"0","seen":"1","sim_slot":"0","spam_report":"0","status":"-1","sub_id":"-1","svc_cmd":"0","teleservice_id":"0","thread_id":"4","type":"2" },{ "_id":"32","address":"0813132204","app_id":"0","body":"Boo..who goes there aaa","date":"1477483120209","date_sent":"0","deletable":"0","error_code":"0","hidden":"0","locked":"0","msg_id":"0","pri":"0","read":"1","reserved":"0","roam_pending":"0","safe_message":"0","seen":"1","sim_slot":"0","spam_report":"0","status":"-1","sub_id":"-1","svc_cmd":"0","teleservice_id":"0","thread_id":"5","type":"2" }]';

    var textSMSA = '[{ "address":"0813132204","body":"Boo..who goes there bbb" },{ "address":"0813132204","body":"Boo..who goes there aaa" }]';

    var objSMS = JSON.parse(textSMS);
    var objSMSA = JSON.parse(textSMSA);

    console.log(textSMS);
    console.log(objSMS);

    if(SMS) SMS.restoreSMS(objSMS, function( n ){

        console.log(n + ' sms messages restored');

    }, function(err){
        console.log('error restore sms: ' + err);
    });     

}

Android M wont ask for sms permissions

I have an app that listen to incoming sms to detect confirmation code for registration action and on android M it does not request the permissions to the user so it does not detect the incoming sms.

Previously versions 4 >= 5 <= works just fine.

UPDATE:

if y try to send an SMS i get this error

uid 10147 does not have android.permission.SEND_SMS.

How can we force android to request SMS rights

Demo Does not even really run

I copied the example and run on my phone in debug mode nothing works just the app shows but not a single function works

Crash on "onSMSArrive"

Cannot manage to catch "onSMSArrive" event. Whenever an SMS arrives into the phone my application just crashes. Any ideas?

Lenovo S960 on Android 4.4.2

what is date and date_sent

Hello,
Thank you for sharing this plugin.
I wonder how i can interpret data and data_sent when using SMS.listSMS
i have negative and positive values like 87836432 84298513 -61491568, i have tried combinations with current SMS.listSMS call time, but did not get hot to interpret them.
would you please help me.
Regards,
Jamal

"onSmsArrive" is triggered only once

I am using this plugin with ionic framework. After initializing the watch by SMS.startWatch() , it works well when the first SMS arrives. But it does not broadcasts any event for subsequent messages.

body and indexFrom filter not working

Hi floatinghotpot, I am trying to search content from sms inbox and I am having 1000 sms.

I am using the below filter as given in the doc but facing the below issues:

i. "body" filter is not working alone. While I am applying both "address" and "body" it is working as expected.
ii. When changing the index value of "indexFrom" filter from 0 to anyother value, it is returning zero result.

 var filter = {
                box : 'inbox', // 'inbox' (default), 'sent', 'draft', 'outbox', 'failed', 'queued', and '' for all
                address : '+8613601234567', // sender's phone number
                body : 'This is a test SMS', // content to match
                // following 2 filters can be used to list page up/down
                indexFrom : 0, // start from index 0
                maxCount : 10, // count of SMS to return each time
            }; 

I think this is the issue with the plugin. Please look into the issue and let me know.

Long message break in parts

Incoming message body length is greater then 160 character. It break the message into two parts. Is it any way to get a single message of whole body.

Uncaught TypeError: Cannot read property 'indexOf' of undefined

var textmsg = pesanku;

            if(sendto.indexOf(";") >=0) {
                sendto = sendto.split(";");
                for(i in sendto) {
                    sendto[i] = sendto[i].trim();
                }
            }
            if(SMS) SMS.sendSMS(sendto, textmsg, function(){}, function(str){alert(str);});

Cannot read property 'indexOf' of undefined

License query

As mentioned in the docs here
The plugin is FREE to use.

While using the plugin I found that the SMS list feature of the plugin require a license key to list more thatn 10 SMSes.

But sending SMSes does not have such limit.

So does the license apply to only listing SMSes or the entire functionality?

Read Blog here.

Intercept not working

I am using this plugin and loving it. Thanks and keep up the good work.

Everything else works fine except that found that when i use intercept the sms still goes through to the default sms app.

I am using cordova 5.0.0 and have checked for android 4.4.2 and 5.0

I am using the following code for intercept

     interceptTrue(){
         if(SMS) SMS.enableIntercept(true, function(success){
              console.log("interceptTrue  "+ success);
              }, function(error){
             console.log("interceptTrue "+error);
           });
      }

I am not getting any errors and when the success callback returns "OK".

Notice that i am using the first parameter as Boolean true, From what i could tell that is the correct way but do let me know otherwise.

-Thanks

Plugin not found on iOS

Installed using the following command:
cordova plugin add com.rjfun.cordova.sms

got this message:
Plugin 'SMS' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml
with Cordova 5.1.1.
On Android, it works perfect.

Am I missing something?

Ionic 2 rc3 Configuration

Hello all
Can anyone help me get this great plugin working inside an Ionic 2 rc3 application please?
Thank you
Eric

Sending Multipart SMS

Is this plugin able to sending multipart sms? I mean long sms with same ID.
Thanks

List all sms

currently only 10 sms are disaplyed. how to list all sms.
what is the use of filter and there are no docs.
if u could have added a donate button people would have supported u but u seems too greedy.
how could 1 pay 30$ when i canot confirm the whole plugins with params etc.

SMS To Number ?

Hi @floatinghotpot , Is it possible to get the mobile number "TO" which the receiving SMS has been sent ? Current object shows the MessageCenter and address.
My Use case is i have written an app which runs on dual sim phone and triggers service call when sms received. Here i want to put some logic which changes depending on the number on which SMS received.

Regards,
Hemant

Restore sms doesn't work

Hi there.I try this plugin but I find the restore function doesn't work.
After Android 5.0, the system will ignore any inserts into sms db except inserts from sms application that user chose. So before insert, we should ask user to chose cordova activity as the default sms application. That's easy.

if (!this.cordova.getActivity().getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(this.cordova.getActivity()getApplicationContext()))) {
              Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
              intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, this.cordova.getActivity().getPackageName());

              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              try {
                  this.cordova.getActivity().startActivity(intent);
              } catch (Exception e) {
                  e.printStackTrace();
              }
}

Then you have to add some service to AndroidManifest.xml.

<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.SENDTO" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="sms" />
                <data android:scheme="smsto" />
                <data android:scheme="mms" />
                <data android:scheme="mmsto" />
            </intent-filter>
        </activity>
        <receiver android:name=".commonComponent.backupComponent.EmptySmsReceiver" android:permission="android.permission.BROADCAST_SMS">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_DELIVER" />
            </intent-filter>
        </receiver>
        <receiver android:name=".commonComponent.backupComponent.EmptyMmsReceiver" android:permission="android.permission.BROADCAST_WAP_PUSH">
            <intent-filter>
                <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
                <data android:mimeType="application/vnd.wap.mms-message" />
            </intent-filter>
        </receiver>
        <service android:exported="true" android:name=".commonComponent.backupComponent.EmptyService" android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
            <intent-filter>
                <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="sms" />
                <data android:scheme="smsto" />
                <data android:scheme="mms" />
                <data android:scheme="mmsto" />
            </intent-filter>
        </service>
    </application>

I make the restore function work in this way.But I don't know if there is another way because this is a plugin and a plugin shouldn't edit AndroidManifest.xml.
Looking forward to a better solution. :)

How can i listen when app is total closed?

onSMSArrive works win background and foreground very fine, but i need a listen even if the user close (kill) the app.
How can i register in android s.o. this listen?

listSMS problem- lists messages for numbers with area code only

I tried to list all sms for one contact. For the native sms application, sms address with area code (+911234567890) and without area code (1234567890) is same. But the plugin cannot list the sms that were sent without the area code (say to 1234567890). Am I missing anything. I tried with Android 6.0.

Reading OTP from users Mobile automatically

Hi,
I am currently working on an app where after the user enters the phone number during registration process, an auto generated OTP is sent to his/her mobile. In the very next page he/she needs to put the OTP and hit next so that he/she can set the password. Now I want to automate the process , like when OTP comes my app should be able to detect and autofill the OTP input box.

Using Meteor 1.3.3
Cordova for generating mobile apps

Thank You

Valid license

From readme file:

A valid license is required to get email support, or use it in commercial product.

It is specified that this plugin uses MIT license, but what actually is included in this "valid license"? The project can be modified? Ca be used as a base for another open source project with MIT license?

sendSMS returns success when failure has occurred due to no credit remaining on phone

sendSMS returns success when failure has occurred due to no credit remaining on phone

Code used to demonstrate fault on a Galaxy Young 2 (Android) phone using O2 payg sim:

var number = "xxxxxxxxxxx";
var message = "Hello there";
var success = function (e) { alert('Message sent successfully ' + e); }; //e returns 'OK'
var error = function (e) { alert('Message Failed:' + e); };
if(SMS) SMS.sendSMS(number, message, success, error);

listSMS problem

I have tried to use the listSMS method and it seems to work ok. But I have problems with interpreting two fields in the JSON file that it returns. The two fields are date_sent and date. They contain just numbers, so I guess they are supposed to be UNIX style dates (i.e. milliseconds from the epoch). Is that a correct assumption? When accessed from javascript though, they are sometimes negative and they appear to be to small. Is there a conversion problem between Java and Javascript?

onSMSArrive not working more in adroid 6.0.0

Hello,

I had a device with android 4.4.4 kitkat. The event 'onSMSArrive' work in it. But in android 6.0.0 marshmallow this event not work more.

Someone could help me the reason about this.

sendSMS do no action in ios

hi, i used this plugin in my android - ionic framework app, now i want to do the ios side, but something ging wrong,

when the execute reach the line

SMS.sendSMS( ........

nothing happen , no error in console .. no sms sent .. nothing !!

any help ?

Cordova Plugins (cordova-plugin-sms) works on Android 4.1.2 but not on Android 4.4.2 (Samsung Galaxy Note GT-N8000)

I successfully installed my app, but have a problem with cordova-plugin-sms.

It's working on Android 4.1.2 and 6.0.0 but not on 4.4.2 .
When I use the app on Android 4.4.2, the app is working but the plugin does work. I DO get an alert message saying "SMS is not supported". So I cannot send an SMS to another mobile,
The plugin to operate SMS send/intercept/list so, I am using cordova-plugin-sms

How can I fix it?

Hi, Herewith I have sent the below tested project links which I used for Android 4.4.2. I find error while executing the test link project. How can I fix it and do you have anyother sms plugin for Android 4.4.2?

Link : test project

SMS text limit

Does the plugin has some limit for the number of letters that a SMS can contain ? Since when I try to send with 159 characters its fine, but if its 160+ its not sending the message

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.