Git Product home page Git Product logo

cordova-sms-plugin's Introduction

Cordova SMS Plugin

Cross-platform plugin for Cordova / PhoneGap to to easily send SMS. Available for Android, iOS, Windows Phone 8 and Windows 10 Universal.

Installing the plugin

Using the Cordova CLI and NPM, run:

$ cordova plugin add cordova-sms-plugin

It is also possible to install via repo url directly (unstable), run :

cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git

Using the plugin

HTML

<input id="numberTxt" placeholder="Enter mobile number" value="" type="tel" />
<textarea id="messageTxt" placeholder="Enter message"></textarea>
<input type="button" onclick="app.sendSms()" value="Send SMS" />

Javascript

var app = {
    sendSms: function() {
        var number = document.getElementById('numberTxt').value.toString(); /* iOS: ensure number is actually a string */
        var message = document.getElementById('messageTxt').value;
        console.log("number=" + number + ", message= " + message);

        //CONFIGURATION
        var options = {
            replaceLineBreaks: false, // true to replace \n by a new line, false by default
            android: {
                intent: 'INTENT'  // send SMS with the native android SMS messaging
                //intent: '' // send SMS without opening any other app, require : android.permission.SEND_SMS and android.permission.READ_PHONE_STATE
            }
        };

        var success = function () { alert('Message sent successfully'); };
        var error = function (e) { alert('Message Failed:' + e); };
        sms.send(number, message, options, success, error);
    }
};

On Android, two extra functions are exposed to know whether or not an app has permission and to request permission to send SMS (Android Marshmallow +).

var app = {
    checkSMSPermission: function() {
        var success = function (hasPermission) { 
            if (hasPermission) {
                sms.send(...);
            }
            else {
                // show a helpful message to explain why you need to require the permission to send a SMS
                // read http://developer.android.com/training/permissions/requesting.html#explain for more best practices
            }
        };
        var error = function (e) { alert('Something went wrong:' + e); };
        sms.hasPermission(success, error);
    },
    requestSMSPermission: function() {
        var success = function (hasPermission) { 
            if (!hasPermission) {
                sms.requestPermission(function() {
                    console.log('[OK] Permission accepted')
                }, function(error) {
                    console.info('[WARN] Permission not accepted')
                    // Handle permission not accepted
                })
            }
        };
        var error = function (e) { alert('Something went wrong:' + e); };
        sms.hasPermission(success, error);
    }
};

FAQ

sms is undefined

Please go through all the closed issues about this subject. The issue is mostly coming from the way you installed the plugin, please double check everything before opening another issue.

Android: INTENT vs NO INTENT

If sending a SMS is a core feature of your application and you would like to send a SMS with options = { android: { intent: '' } }, you need to fill this form. If it is not a core feature of your application, you have to use options = { android: { intent: 'INTENT' } }. Please, read this page to learn more.

When building my project for android I get the following error: cannot find symbol: cordova.hasPermission(string)

You need to update cordova-android to the latest version (recommended), or at least to the version 5.1.1.

cordova platform update android or cordova platform update [email protected]

Is the plugin available on Adobe PhoneGap Build?

Yes, the plugin is available, please see instructions here: http://docs.phonegap.com/phonegap-build/configuring/plugins/. Use the npm or github source.

How can I receive SMS?

You can't receive SMS via this plugin. This plugin only sends SMS.

Android immediately passes success back to app?

Please read #issue 26

iOS closes the SMS dialog instantly. What's wrong?

Make sure the number argument passed is converted to string first using either String(number) or number.toString(). Notice that toString() won't work if the number argument is null or undefined.

I get this error. What's wrong?

compile:
    [javac] Compiling 4 source files to /Users/username/MyProject/platforms/android/bin/classes
    [javac] /Users/username/MyProject/platforms/android/src/org/apache/cordova/plugin/sms/Sms.java:15: cannot find symbol
    [javac] symbol  : class Telephony
    [javac] location: package android.provider
    [javac] import android.provider.Telephony;
    [javac]                        ^
    [javac] /Users/username/MyProject/platforms/android/src/org/apache/cordova/plugin/sms/Sms.java:60: cannot find symbol
    [javac] symbol  : variable KITKAT
    [javac] location: class android.os.Build.VERSION_CODES
    [javac]     if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    [javac]                                                    ^
    [javac] /Users/username/MyProject/platforms/android/src/org/apache/cordova/plugin/sms/Sms.java:61: package Telephony does not exist
    [javac]       String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this.cordova.getActivity());
    [javac]                                               ^
    [javac] 3 errors

BUILD FAILED

The problem is that you need to make sure that you set the target to android-19 or later in your ./platforms/android/project.properties file like this:

# Project target.
target=android-19
How can I send an sms in my iOS app without passing control to the native app like it can be done on Android?

This isn't possible on iOS. It requires that you show the user the native sms composer, to be able to send an sms.

Donations

If your app is successful or if you are working for a company, please consider donating some beer money ๐Ÿบ:

paypal

Keep in mind that I am maintaining this repository on my free time so thank you for considering a donation. ๐Ÿ‘

Contributing

I believe that everything is working, feel free to put in an issue or to fork and make pull requests if you want to add a new feature.

Things you can fix:

  • Allow for null number to be passed in Right now, it breaks when a null value is passed in for a number, but it works if it's a blank string, and allows the user to pick the number It should automatically convert a null value to an empty string

Thanks for considering contributing to this project.

Finding something to do

Ask, or pick an issue and comment on it announcing your desire to work on it. Ideally wait until we assign it to you to minimize work duplication.

Reporting an issue

  • Search existing issues before raising a new one.

  • Include as much detail as possible.

Pull requests

  • Make it clear in the issue tracker what you are working on, so that someone else doesn't duplicate the work.

  • Use a feature branch, not master.

  • Rebase your feature branch onto origin/master before raising the PR.

  • Keep up to date with changes in master so your PR is easy to merge.

  • Be descriptive in your PR message: what is it for, why is it needed, etc.

  • Make sure the tests pass

  • Squash related commits as much as possible.

Coding style

  • Try to match the existing indent style.

  • Don't mix platform-specific stuff into the main code.

History

License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cordova-sms-plugin's People

Contributors

aharris88 avatar andreszs avatar cedriclombardot avatar dbaq avatar eddyverbruggen avatar ferdil avatar fredrikeldh avatar gion avatar gotling avatar jlkalberer avatar kentmw avatar lajith111 avatar legagneur-matthieu avatar lev09 avatar maihannijat avatar maikueo avatar maistho avatar piterden avatar rk-7 avatar rodinhaker avatar shazron avatar vkeepe avatar vo2le 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

cordova-sms-plugin's Issues

Publish to NPM

Can you publish this plugin to NPM so we don't have to use git?

How to put Carriage Return in Message

Love your plug in.
I need to be able to programmatically insert some carriage returns into the message text.
Is there any way to do that?
TIA
Bob

phone number format

I load in my contact's phone numbers and then send sms. The sms will send to some contacts but not others. I think it is due to how the contact's phone numbers are formatted.

415 279-5665 // will not send
+1 909-851-1662 // will send

What are the rules about formatting phone numbers in order to send sms?

Pass an options object instead of passing a specific string for the android intent

So far, the third parameter is a string specific for the android platform ('intent' or ''), it should be replaced by an option object containing (future) global configuration and platform specific configuration. It should also be backward compatible with the current version (i.e. if somebody passes a string instead of an object it must work)

here is a suggestion for the structure of the options:

{
    globalConf: true,
    globalConf2: false,
    android: {
        intent: '', //or 'INTENT'
        androidConf: true,
    },
    ios: {
        iosConf: false
    },
    wp8: {
        wp8Conf: false
    }
}

if nothing is passed, we will use default values.

Unknown provider: $cordovaSmsProvider <- $cordovaSms

I have added the cordova plugin and included the $cordovaSms to my controller.

It is prompting "Unknown provider: $cordovaSmsProvider <- $cordovaSms".

Please help on what is missing part in this. Is there any javascript file that I need to refere.

Tests?

In the readme you said "Make sure the tests pass", but there aren't any tests, right? Are you planning on adding unit tests? or is that a mistake in the readme?

I have no idea how you would even unit test this plugin, or cordova plugins in general, but if it's possible, I think it's a great idea.

Can't make it send an sms with my code?

Hey guys!

I tried to use this very nice plugin, but I can't make it send an sms?

My code is

var app = {

sendSms: function() {
    var number = '28159518';
    var message = 'In need of help at these cords: ' + cords; (Cords is set earlier with geoposition)
    alert(number); (shows the alert correct)
    alert(message); (shows the alert and with the correct data)

    //CONFIGURATION
    var options = {
        replaceLineBreaks: false, // true to replace \n by a new line, false by default
        android: {
            intent: 'INTENT'  // send SMS with the native android SMS messaging
            //intent: '' // send SMS without open any other app
        }
    };

    alert("Test before send"); (shows the alert correct)
    var success = function () { alert('Message sent successfully'); };
    var error = function (e) { alert('Message Failed:' + e); };
    sms.send(number, message, options, success, error);
    alert("Test after send"); 
    (This alert or the succes/error never comes, which leads me to think it never execute sms.send?)
}  

};

Hope you can help me with this little issue

Kind regards,
Maik

The main app closes when opening android's native message window

As stated above, when the android's native message window appears.. My app closes.. Please check my code below.

This is only happening on android. Not happening on iOS.

$scope.sendSMS = function(details) {
var number = 'xxxxxxx';
var message = "Some message here";

    var options = {
        replaceLineBreaks: false, // true to replace \n by a new line, false by default
        android: {
            intent: 'INTENT'  // send SMS with the native android SMS messaging
        //intent: '' // send SMS without open any other app
        }
    };

    var success = function () {
        //success code here
    };
    var error = function (e) {
        //error code here
    };
    sms.send(number, message, options, success, error);
}

Linking issues on arm64

MFMessageComposeViewController gives me issues complaining about undefined symbols. I already tried removing and adding frameworks like MessageUI and CoreTelephony. However that didn't change anything.

I have little experience in native iOS development. Could someone help me out?

Trying to remove/add the frameworks again helped... no idea why it didn't work the first time.

Dual Sim supported..

Hi,

This plugin is not dual sim supported please any one help me how to fix this.

Help please

Thank you!

iOS 8 support

@ninapratiwi reported: ```So recently I use AngularJs to use this plugin

Here's the code:
$scope.sendText = function(){

            var intent = "INTENT";
            var success = function(){alert("Sent SMS successfully"); };
            var error = function(e){alert("Message Failed "+e); };
            alert("Values:\nNumber:"+$scope.number+
                    "\nMessage:"+$scope.text+
                    "\nIntent:"+intent);

            sms.send($scope.number, $scope.text, intent, success, error);

};
No error but not running..
it doesn't return success or error..

Checked the plugin is not broken..
everything is inside..

does it because I run it on ios 8..?```

ios sms app

hi, is there any way to send the sms in ios without opening the ios default sms app ? i mean send the sms in the background ?

thanks

Send sms without launching native ui (programmically)

Hello, first of all thanks for great plugin! Keep up the good work!

I have a quick question, is there a way to send multiple sms messages without launching android UI?
something like:

var arrayPhoneNumbs = ['465','4653','65465465'];

forin(num in arrayPhoneNumbs){
  num.send sms and wait until done,
  notify js that this one is a success 
}

Anybody have any suggestions?

Thanks a lot

Disable intent permission android

Is there anyway I can disable the intent permission if I won't be using it? I don't like the permission on my app that says "this might cost you money"

I'm only using the plugin to populate an SMS. Thank you!

Message not sent on iOS 8.3

I tried to send message on iOS 8.3 but it's not working.
Here is my code;
var success = function () { console.log('Message sent successfully'); };
var error = function (e) { console.log('Message Failed:' + e); };
var options = {
replaceLineBreaks: false
};

sms.send(recipient.mobileNumber, $scope.message.body, options, success, error);
console.log('end');

I can see log 'end' but cannot see success message or fail message.
How can I solve this?

Can not send multiple messages

when i try to send multiple messages only the firs one is complete.
var options = {
replaceLineBreaks: false,
android: {
intent: ''
}
};

$cordovaSms
.send("123456,123456", new Date().getTime() ,options)
.then(function() {
toast('Success');
// Success! SMS was sent
}, function(error) {
toast('Error');
// An error occurred
});

In the platform android always triggered success event before send the sms

In the platform android always return success event before send the sms

run the example code in IOS succefully but in android triggered success before send

 //CONFIGURATION
       var options = {
           replaceLineBreaks: false, // true to replace \n by a new line, false by default
           android: {
               intent: 'INTENT'  // send SMS with the native android SMS messaging
               //intent: '' // send SMS without open any other app
           }
       };

       var success = function () { alert('Message sent successfully'); };
       var error = function (e) { alert('Message Failed:' + e); };
       sms.send(62646345, 'Hello World', options, success, error);

thx

Android immediately passes success back to app?

The iOS composer waits to see if the message was sent or cancelled and fires the right callback. The Android version immediately fires success whether they end up sending or not.

There is not a way to make Android behave like iOS correct?

(this is using INTENT)

cordova-sms-plugin

https://github.com/cordova-sms/cordova-sms-plugin
I installed the plugin very much correctly. The cordova version i m using is 2.8.

First i got error as "uncaught reference error - module not defined" then in sms.js file i defined the module as var module={}; which resolved that error. But then i m getting another error.

The new error i m getting is "uncaught reference error - SMS not defined". I request you to please help me. I m struglling with this sms plugin since last two days and till no output. Error is coming at this line.

sms.send(number, message, options, success, error);

Any help will be much appreciated.

Create Git tag for v0.1.4

Since cordova plugin add doesn't appear to support a specific Git commit, could you tag v0.1.4 (and v0.1.3)?

SMS History

Hello,

I was wondering if there is a way to tell to Android to not save the message sent with the empty intent ?
Actually when I send a message, it is saved directly in sms history in the sms app.

Thanks

sms not defined

I keep getting a reference error in my console stating that sms can't be defined.

All sms.js files are in the correct location.

How can I troubleshoot and solve this?

I am unable to send message in backend

Hello,

I started working on phone gap and I got requirement like, send sms in back end. I am trying your plugin. When I click on "send sms" button. It is opening hangouts. I tried both options available in your example. But I am unable to send back end.

Can you please help me in this.

Thanks,
Satya

Open Default Sms Display When Sending SMS

Hi There,

I have question, why when I am sending a sms, it was displaying the default sms display from android? why not just send my message right away without opening the android sms default GUI?

only error callbacks are called

@raghav14 reported: When ever i call any method (isSupported, startReception), it called error callbacks only, I have checked for permission also, but still the same result.

How to prepopulate the message content in android?

Hello all,
I am trying to use this plugin in a test app which was successful in IOS(I mean the number and the message i am entering in the textbox is getting prepopulated in the native SMS Composer of IOS) but in Android its only populating the number field but the message is empty how can i fix this issue??

I took online build and tested and the plugin version i tried up is 0.1.2 and the Android platform version is Lollipop no issue with kitkat powered device,someone kindly help me to fix this issue.

Support to read SMS

It would be a great addition to have support for reading SMS from the phone (android and other if supported).

SMS plugin with Adobe Build

Hi,

I'm trying to use this SMS plugin with Adobe Build and I'm failing miserably. I'm able to use a few other plugins but this one just doesn't work.

I'm missing something simple but...
I've added this to my confg.xml: <gap:plugin name="com.cordova.plugins.sms" version="0.1.2" />

I've added this to the index of my HTML5 project:

<script type="text/javascript" src="cordova.js"></script>

And I'm probably missing something because I get errors like "sms is not defined"
And when I'm including sms.js I get an error like this:
"Cannot read property 'send' of undefined"

Apparently I'm unable to address the js functions in the right way,

Any help would be great, :-)
Thanks,

Michael

Ps the code I'm using is the basic example provided by you.

Multiple recipients problem

Hello,

I have a problem with sending SMS to multiple recipients, I tried with separating with , or ; but only the first number listed is receiving the message in both cases.

Here is the code:

var options = {
  replaceLineBreaks: false,
  android: {
      intent: ''
  }
};

var success = function () { alert('sent !'); };
var error = function (e) { alert('error ! '+e); };
sms.send('010000000,020000000,030000000', 'my message', options, success, error);

I tried on Android 4.4 or Android 5.0
Is there something else I can try or is this a bug ?

Thank you

iOS intent

Hi!
Is it possible to send a SMS from the app on iOS without exiting the app? I have tried the intent option but in doesn't work.
My phone runs on iOS 8.3.

Thanks! :)

iPhone 6, 8.2 Input & Keyboard Disappear

Just installed the cordova-sms-plugin and love it. However, I noticed an issue where the input and keyboard disappear almost instantly when it shows the native iMessage screen. It's there, flickers and disappears. If I then click on the input field to add contacts it'll come back showing the message I am trying to send and the keyboard.

Has anyone else run into this issue? Any resolution?

My options are the default suggested per the README.

sms not defined

@Stormgun reported: Hello, I've added the plugin and i checked if the scripts and java file are in the right places and they are but I am using angular for my scripts, and I am getting an sms undefined error in the console

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.