Amazon Ad

Sunday 6 May 2012

Send SMS Using Android Phonegap

Hi Folks!,

Hope you have enjoyed the previous posts and got the working knowledge of the android. Today we are going to do some different stuff using the PhoneGap Open Source Through which we can do lot many things on cross platform mobile phones. Please read the help file with phonegap and then read the following code. The code here would send the sms using the phonegap plugin.

Step 1. Install Phonegap from http://phonegap.com/.

Step 2. Install The plugins for phonegap available on github.

Step 3. Look for SmsPlugin folder and copy the smsplugin.java into your "src" folder in eclipse.

Step 4. Add the following code in your html file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=320; user-scalable=no" />
<title>Send SMS</title>
   
    <link href="css/style.css" rel="stylesheet" type="text/css" />

    <script src="jquery-1.6.min.js" type="text/javascript" />

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

    <script src="jquery.mobile-1.0b3.min.js" type="text/javascript" />

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

<script type="text/javascript">             
        function onDeviceReady () {
            $('#send').bind('click', function () {
               
                window.plugins.sms.send($('#phone').val(), $("#txtMessage").val(),
                    function () {
                       alert('Your Message has been sent successfully.');   
                       $("#txtMessage").val("");
                    },
                    function (e) {
                        alert('Sorry There Was An Error :' + e);
                    }
               
                );
              
            });                           
        }
</head>
<body>
        <dl>
            <dt style="width: 80px; margin-left: 18px">Message</dt>
            <dd>
                <textarea rows="3" cols="23" id="txtMessage" name="txtMessage"></textarea></dd>
        </dl>
        </div>
        <div class="info" style="text-align: center">
            <img id="send" src="images\button.jpg" />
        </div>
</body>

Step 5: Modify plugins.xml and add the following line

<plugin name="SmsPlugin" value="ritesh.tandon.sendsms.SmsPlugin" />

here instead of ritesh.tandon.sendsms write your package name and class name.

Thats it folks! , you are ready for the show.

Thnx
Ritessh

 

2 comments:

mohsenmomeni said...

this not work
TypeError: Result of expression 'window.plugins' [undefined] is not an object. at file:///android_asset/www/index.html:20
please help

Ritesh said...

Please include the xml folder that comes with the phonegap in your project. and also add the code for the plugin in your plugin.xml file.

Post a Comment

Comments are welcome, Please join me on my Linked In account

http://in.linkedin.com/pub/ritesh-tandon/21/644/33b

How to implement Captcha v3 in ASP.NET

 I was facing an issue of dom parsing in my website. I finally resolved it by using Google Captcha V3. Step 1: Get your keys from https:...