1.获取短消息,
MTK没有专门用于获取短消息内容的函数,这给我们操作短消息带来了不便.比如有时我们需要分析短消息的内容,再比如有时要把短消息写入T卡了,再或者有时要把某条短消息显示到某些应用场合了,这时就需要获取短消息的内容.这里提供一个我经常使用的接口:
#include "SMSApi.h"
#include "med_utility.h"
extern unsigned short mmi_frm_sms_show_list_index[];
S8 g_sms_buffer[160] = {0};
char *ConvertString(char * str)
{
char temp;
int i;
int len = wstrlen(str);
for (i = 0; i < len ; i += 2)
{
temp = str[i];
str[i] = str[i+1];
str[i+1] = temp;
}
return str;
}
int wstrlen(char * txt)
{
int lenth=0;
unsigned char * ss=(unsigned char*)txt;
while(((*ss<<8)+*(ss+1))!=0)
{
lenth+=2;
ss+=2;
}
return lenth;
}
void my_msg_get_msg_rsp(void* data, module_type mod, U16 result)
{
//U8 type=*(U8*)data;
EMSData*pEms;
int len = 0;
GetEMSDataForView (&pEms, 0);
len = wstrlen((char *)(pEms->textBuffer))+2;
//把获取的信息复制到g_sms_buffer以备使用
if (len < 20)
{
memcpy(g_sms_buffer, pEms->textBuffer, len);
}
else
{
memcpy(g_sms_buffer, pEms->textBuffer, 20);
}
}
// type: MMI_FRM_SMS_APP_INBOX, MMI_FRM_SMS_APP_OUTBOX, MMI_FRM_SMS_APP_DRAFTS
// index: 0~0XFF
S32 my_msg_get_msg_req (U8 type, U16 req_index, E_MTPNP_AD_FILTER_RULE cur_sim)
{
int count =0;
U16 index;
/* disallow re-entering SMS application when there is a pending SMS job running in the background */
if(mmi_frm_sms_check_action_pending())
{
return 1;
}
#ifdef __MMI_DUAL_SIM_MASTER__
if(cur_sim == MTPNP_AD_FILTER_MASTER)
{
MTPNP_AD_SMS_Set_Filter_Rule(MTPNP_AD_FILTER_MASTER);
count =MTPNP_PFAL_SMS_Get_SMS_List_Size(type);
}
else
{
MTPNP_AD_SMS_Set_Filter_Rule(MTPNP_AD_FILTER_SLAVE);
count = MTPNP_PFAL_SMS_Get_SMS_List_Size(type);
}
if((count <=0)||(req_index >= count))
{
return -1;
}
MTPNP_PFAL_SMS_Set_Current_Index(req_index);
index = mmi_frm_sms_show_list_index[req_index];
#else
index = req_index;
#endif
mmi_frm_sms_read_sms(my_msg_get_msg_rsp, MOD_MMI, type, index, MMI_TRUE);
return 0;
}
2.发短信,有时我们需要向网络或者别的基站发送一条自填充内容的短信.比如订阅某种服务,或者查询话费,或者定时发送短信,或者拒接电话时给MT发一条提示短信等场合.函数有5个参数,mobileNo为手机号码,ASC类型字串,mobileNoLen号码长度,smsMsg短消息内容,应为UCS2编码,smsMsgLen长度,simid双卡情况下,0为主卡,1为副卡
#include "SMSApi.h"
#include "ProtocolEvents.h"
#ifndef __MMI_DUAL_SIM_MASTER__
void my_send_sms(S8 mobileNo[], U32 mobileNoLen, U8 smsMsg[], U32 smsMsgLen)
#else
void my_send_sms(S8 mobileNo[], U32 mobileNoLen, U8 smsMsg[], U32 smsMsgLen,
U8 simid)
#endif
{
mmi_sms_send_msg_req_struct *sendSms;
sendSms = (mmi_sms_send_msg_req_struct*)OslConstructDataPtr(sizeof(*sendSms));
sendSms->dcs = SMSAL_UCS2_DCS;
sendSms->udhi = 0;
sendSms->length = smsMsgLen;
memset(sendSms->msg,0,SMSAL_MAX_MSG_LEN);
memcpy(sendSms->msg,smsMsg,sendSms->length);
sendSms->profile = 0;
sendSms->para = 0;
sendSms->reply_index = MMI_FRM_SMS_INVALID_INDEX;
sendSms->dest.type = CSMCC_DEFAULT_ADDR_TYPE;
memset((S8*)sendSms->dest.number,0,MAX_CC_ADDR_LEN);
sendSms->dest.length = mobileNoLen;
memcpy(sendSms->dest.number,mobileNo,sendSms->dest.length);
sendSms->seq_num = 0;
sendSms->mms_mode = 0;
//simsp_set_sms_ProtocolEventHandler();
#ifndef __MMI_DUAL_SIM_MASTER__
mmi_frm_sms_send_message(MOD_MMI,MOD_L4C,0,PRT_MSG_ID_MMI_SMS_SEND_MSG_REQ,(
oslParaType*)sendSms,NULL);
#else//__MMI_DUAL_SIM_MASTER__
if(simid == 0)
{
mmi_frm_sms_send_message(MOD_MMI, MOD_L4C, 0,PRT_MSG_ID_MMI_SMS_SEND_MSG_REQ
, (oslParaType *)sendSms, NULL);
}
else
{
MTPNP_PFAL_Send_Message_Segment((void *)sendSms);
}
#endif//__MMI_DUAL_SIM_MASTER__
}