`
rexsee
  • 浏览: 20063 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Rexsee API介绍:SMSSender短信发送

阅读更多

 

rexseeSMSSender扩展,实现短信发送与事件回调。

 

【函数】 void send(String phoneNumber, String message)

【说明】 发送短信。

【返回】

【参数】

phoneNumber:目标手机号码。

message:短信内容。

 

【函数】 void send(String id, String phoneNumber, String message)

【说明】 发送短信并回调事件。

【返回】

【参数】

id:任意的ID,在事件onSmsSent和onSmsDelivered中标识该条短信,如果为空,则onSmsSent和onSmsDelivered不会被调用。

phoneNumber:目标手机号码。

message:短信内容。

 

【事件】 void onSmsSent(String id, String result)

【说明】 调用send()函数后,如果id不为空,当短信发送完毕时触发。

【参数】

id:短信的自定义id。

result:发送结果,如果成功返回"OK",否则返回错误信息。

 

 

【事件】 void onSmsDelivered(String id, String pdu)

【说明】 调用send()函数后,如果id不为空,当短信发送到接收方时触发,注意,触发该事件可能需要较长时间,取决于网络状况。

【参数】

id:短信的自定义id。

pdu:发送报告。

 

详细java源码:rexseeSMSSender.java

 

/* 
* Copyright (C) 2011 The Rexsee Open Source Project 
* 
* Licensed under the Rexsee License, Version 1.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*      http://www.rexsee.com/CN/legal/license.html 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 
 
package rexsee.communication;  
 
import java.util.ArrayList;  
 
import rexsee.core.browser.Browser;  
import rexsee.core.browser.clazz.JavascriptInterface;  
import android.app.Activity;  
import android.app.PendingIntent;  
import android.content.BroadcastReceiver;  
import android.content.Context;  
import android.content.Intent;  
import android.content.IntentFilter;  
import android.telephony.SmsManager;  
 
public class RexseeSMSSender implements JavascriptInterface {  
 
       private static final String INTERFACE_NAME = "SMSSender";  
       @Override  
       public String getInterfaceName() {  
               return mBrowser.application.resources.prefix + INTERFACE_NAME;  
       }  
       @Override  
       public JavascriptInterface getInheritInterface(Browser childBrowser) {  
               return this;  
       }  
       @Override  
       public JavascriptInterface getNewInterface(Browser childBrowser) {  
               return new RexseeSMSSender(childBrowser);  
       }  
 
       public static final String EXTRA_SMS_ID = "smsID";  
       public static final String EXTRA_SMS_PART = "smsPart";  
       public static final String EXTRA_SMS_PART_TOTAL = "smsPartTotal";  
 
       public static final String ACTION_SMS_SENT = "SENT_SMS_ACTION";  
       public static final String ACTION_SMS_DELIVERED = "DELIVERED_SMS_ACTION";  
 
       public static final String EVENT_ONSMSSENT = "onSmsSent";  
       public static final String EVENT_ONSMSDELIVERED = "onSmsDelivered";  
 
       private final Context mContext;  
       private final Browser mBrowser;  
 
       private String mId = "";  
       private int mTotalSize = 0;  
       private int mSentSize = 0;  
 
       private String getResultString(int resultCode) {  
               switch (resultCode) {  
                       case Activity.RESULT_OK :  
                               return "OK";  
                       case SmsManager.RESULT_ERROR_GENERIC_FAILURE :  
                               return "RESULT_ERROR_GENERIC_FAILURE";  
                       case SmsManager.RESULT_ERROR_NO_SERVICE :  
                               return "RESULT_ERROR_NO_SERVICE";  
                       case SmsManager.RESULT_ERROR_NULL_PDU :  
                               return "RESULT_ERROR_NULL_PDU";  
                       case SmsManager.RESULT_ERROR_RADIO_OFF :  
                               return "RESULT_ERROR_RADIO_OFF";  
                       default :  
                               return "OK";  
               }  
       }  
       private final BroadcastReceiver mSentReceiver = new BroadcastReceiver() {  
               @Override  
               public void onReceive(Context context, Intent intent) {  
                       mSentSize++;  
                       if (mSentSize == mTotalSize) {  
                               context.unregisterReceiver(this);  
                               mBrowser.eventList.run(EVENT_ONSMSSENT, new String[]{mId, getResultString(getResultCode())});  
                       }  
               }  
       };  
       private final BroadcastReceiver mDeliveredReceiver = new BroadcastReceiver() {  
               @Override  
               public void onReceive(Context context, Intent intent) {  
                       context.unregisterReceiver(this);  
                       mBrowser.eventList.run(EVENT_ONSMSDELIVERED, new String[]{mId, intent.getStringExtra("pdu")});  
               }  
       };  
 
       public RexseeSMSSender(Browser browser) {  
               mBrowser = browser;  
               mContext = browser.getContext();  
               browser.eventList.add(EVENT_ONSMSSENT);  
               browser.eventList.add(EVENT_ONSMSDELIVERED);  
       }  
 
       //JavaScript Interface  
       public void send(String phoneNumber, String message) {  
               send(null, phoneNumber, message);  
       }  
       public void send(String id, String phoneNumber, String message) {  
 
               SmsManager sms = SmsManager.getDefault();  
               ArrayList<String> msgs = sms.divideMessage(message);  
               mTotalSize = msgs.size();  
               mSentSize = 0;  
               mId = (id != null && !id.trim().equals("")) ? id : null;  
 
               try {  
                       mContext.unregisterReceiver(mSentReceiver);  
                       mContext.unregisterReceiver(mDeliveredReceiver);  
               } catch (Exception e) {  
               }  
 
               ArrayList<PendingIntent> sentIntents = null;  
               ArrayList<PendingIntent> deliveryIntents = null;  
               if (mId != null) {  
                       sentIntents = new ArrayList<PendingIntent>();  
                       deliveryIntents = new ArrayList<PendingIntent>();  
                       PendingIntent deliverPI = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_SMS_DELIVERED), 0);  
                       for (int i = 0; i < mTotalSize; i++) {  
                               PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_SMS_SENT + "_" + i), 0);  
                               sentIntents.add(sentPI);  
                               mContext.registerReceiver(mSentReceiver, new IntentFilter(ACTION_SMS_SENT + "_" + i));  
                               deliveryIntents.add(deliverPI);  
                       }  
                       mContext.registerReceiver(mDeliveredReceiver, new IntentFilter(ACTION_SMS_DELIVERED));  
               }  
               sms.sendMultipartTextMessage(phoneNumber, null, msgs, sentIntents, deliveryIntents);  
 
       }  
 
}
分享到:
评论

相关推荐

    rexsee jar

    Rexsee是什么 Rexsee是基于Android的HTML5开发平台,帮助开发者使用HTML5+JavaScript开发Android应用。 Rexsee的特点 编程语言使用 HTML5+CSS3+JavaScript+Rexsee扩展API。 超过2000个JavaScript扩展API,功能强大。...

    Rexsee 源代码

    编程语言使用 HTML5+CSS3+JavaScript+Rexsee扩展API。 超过2000个JavaScript扩展API,功能强大。 支持第三方JavaScript开发框架。 B/C/S混合架构,支持应用程序本地化,摆脱网络依赖。 全面支持Android原生UI布局,...

    使用Rexsee EMS开发Android手机应用:为什么及如何开始

    了解使用Rexsee EMS开发Android手机应用的好资料

    rexsee手机本地版开发手册

    rexsee手机本地版开发手册

    rexsee -src.zip

    编程语言使用 HTML5+CSS3+JavaScript+Rexsee扩展API。 超过2000个JavaScript扩展API,功能强大。 支持第三方JavaScript开发框架。 B/C/S混合架构,支持应用程序本地化,摆脱网络依赖。 全面支持Android原生UI布局,...

    Rexsee开发手册的zip文件

    Rexsee是基于Android的HTML5开发平台,帮助开发者使用HTML5+JavaScript开发Android应用。

    rexsee 最新软件源代码

    Rexsee是基于Android的HTML5开发平台,帮助开发者使用HTML5+JavaScript开发Android应用

    Rexsee源代码

    Rexsee源代码,Rexsee系统的源代码。从他的网站上一点一点搞下来的。哈哈。。你懂的。

    rexsee文档和api使用groovy爬下来分享给大家

    NULL 博文链接:https://key232323.iteye.com/blog/1779445

    rexsee非官方菜鸟安装文档

    rexsee目前取消了在线生成功能,只提供了简单的安装指引,但这个指引对于安卓菜鸟来说过于简单,而且其中有几处重大缺漏。本人对官方文档进行了补充说明,并介绍了自己遇到的经验教训,希望对擅长webapp开发,而又不...

    Android移动中间件Rexsee开发手册

    Android移动中间件Rexsee开发手册,利用它可以快速开发Android应用程序,只需要你掌握HTML+CSS+JavaScript,而需要掌握java和Android SDK。让你快速得进入到移动开发的大门。

    开源Rexsee模糊原生应用与Web应用界线

    Web应用,Rexsee,开源,Web开发,JS,Android,Web技术,应用趋势,应用范围,移动终端,,开源Rexsee模糊原生应用与W,开源Rexsee模糊原生应用与Web应用界线

    android使用webwiew载入页面使用示例(Hybrid App开发)

    目前大家所知道的基于中间件的移动开发框架都是采用的 Hybrid 开发模式,例如国外的 PhoneGap、Titanium、Sencha,还有国内的 AppCan、Rexsee 等等。Hybrid App 开发模式正在被越来越多的公司和开发者所认同,相信...

    ESM企业销售管理系统(B/S+mobile) v3.0

    摘要:PHP源码,管理系统,ESM,销售管理系统 ESM企业... 中间件层包括函数库rexsee,由java开发,android操作系统、中间件、用户界面和应用软件组成。    服务器端新增功能模块:  1.客户拜访 2.公告文档 3.产品管理 4

Global site tag (gtag.js) - Google Analytics