简体   繁体   English

在Cordova 3.4中发送短信

[英]Send sms in Cordova 3.4

I am new in cordova 3.4. 我是Cordova 3.4的新手。 I want to write send sms app. 我想编写发送短信应用程序。 I get SMSPlugin from github but i want to write this myself. 我从github获得SMSPlugin,但我想自己写。 I write a html file like this and copy in root/www and i write a java script file in root/www/js. 我写这样的html文件并复制到root / www中,然后在root / www / js中写一个Java脚本文件。 but when i run the app, i don't see button in the page! 但是当我运行该应用程序时,页面上没有显示按钮! Why? 为什么? What is problem? 怎么了 How can i write this app? 我该如何编写此应用程序?

And i change name of java file(Activity) from AndroidManifest manually to my class, this is not a problem, Yes? 我将AndroidManifest中的java文件(活动)的名称手动更改为我的班级,这不是问题,是吗? and i changed 'id' in widget tag from config.xml to my package manually. 我将小部件标签中的“ id”从config.xml手动更改为我的软件包。

index.html: index.html的:

 <html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>


    <script type="text/javascript">
   var txtMSG = "";
        function onDeviceReady(){
            document.getElementById("deviceName").innerHTML= device.model;
            document.getElementById("version").innerHTML= device.cordova;
            document.getElementById("mobilePlatform").innerHTML= device.platform;
            document.getElementById("platformVersion").innerHTML= device.version;
            document.getElementById("uuid").innerHTML= device.uuid;
            document.getElementById("sendSMS").style.display="block";
        }
        function displayTextMessage(msg){
            alert(msg);
            $('#text-messages').prepend('<div>' + msg + '</div>');
        } 
        function sendConsole(){
            var message = "This_is_a_test"
            DeviceInfo.SendConsole({text: message}, function(){
                alert("success");
            }, function(){
                alert("fail");
            });
        }
        function SendSMS(){
            console.log("-------------------Start----------------------");
            DeviceInfo.SendSMS({phoneNumber:[document.getElementById('cellNumber').value], text: document.getElementById('textMessage').value}, function(){
                alert("success");
            }, function(){
                alert("fail");
            });
            console.log("---------------------End--------------------");
        }
        /** Called when browser load this page*/
        function init(){
            document.addEventListener("deviceready", onDeviceReady, false);
        }
    </script>


</head>

<body>
    <input id="sendSMS" style="display:none" type="button" ontouchend="SendSMS()" onclick="SendSMS()" value="Send SMS To:" />
    <!-- <button onClick="SendSMS();">Send SMS</button> <br> -->
    <input id="cellNumber" type="text" style="width:100%" value="9126012134" onclick="this.select()" ontouchend="this.select()" />
    <textarea id="textMessage" style="width:100%; height:100px">Plugin Example</textarea>

    <input id="sendConsole" style="display:none" type="button" ontouchend="sendConsole()" onclick="sendConsole()" value="Send Console Log" />
    <div id="text-messages" style="border:solid 1px #efefef; padding 10px"></div>
</body>



 </html>

DeviceInfo.js: DeviceInfo.js:

  var DeviceInfo = function () { };

  DeviceInfo.callMethod = function (methodName, content, success, fail) {
return PhoneGap.exec(function (args) {
    success(args);
}, function (args) {
    fail(args);
}, 'DeviceInfo', methodName, [content]);
 }

DeviceInfo.GetPhoneNumber = function (content, success, fail) {
  return DeviceInfo.callMethod('getPhoneNumber', content, success, fail);
};

DeviceInfo.SendSMS = function (content, success, fail) {
  return DeviceInfo.callMethod('SendSMS', content, success, fail);
};

DeviceInfo.SendConsole = function (content, success, fail) {
   return DeviceInfo.callMethod('SendConsole', content, success, fail);
};

Thanks for advises 感谢您的建议

There is a plugin on ghithub developed by javatechig here but only work with old cordova/phonegap version. 有通过javatechig开发上ghithub一个插件在这里 ,但只能用老科尔多瓦/ PhoneGap的版本。 This fork https://github.com/aharris88/phonegap-sms-plugin works with recent version of cordova and is updated frequently. 这个fork https://github.com/aharris88/phonegap-sms-plugin与最新版本的cordova一起使用,并经常更新。 Read the "readme.md" for example and more informations. 阅读“ readme.md”以获取示例和更多信息。

This Android Phonegap plugin allows you to easily send SMS in android using both native SMS Manager or by invoking the default android SMS app 这个Android Phonegap插件可让您使用本机SMS管理器或调用默认的Android SMS应用轻松在android中发送SMS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM