|
发表于 2020-8-4 20:19:34
2424 浏览 0 回复
在代码中读取短信内容
有些客户需要在代码里面读取新短信内容,以下代码可以读取。已在2503D,2503AVE上验证过
- CHAR pOutBuffer[2048];
- void mmi_read_sms(U16 msg_id,SrvSmsCallbackFunc callback_func)
- {
- srv_sms_msg_data_struct * msg_data = NULL;
- EMSData* content_ems = NULL;
- // 申请结构体空间
- msg_data = (srv_sms_msg_data_struct*)OslMalloc(sizeof(srv_sms_msg_data_struct));
-
- /* If want to content as EMS format, we need to fill para_flag to SRV_SMS_PARA_CONTENT_EMS */
- msg_data->para_flag = SRV_SMS_PARA_CONTENT_EMS;
- /* For content, its buffer also provided by caller. */
- //申请短信内容存放空间
- msg_data->content_ems = (EMSData*)GetEMSDataForView((EMSData*)&content_ems, 1);
- /* If want to get protocol identifier(PID), we need to fill para_flag to SRV_SMS_PARA_PID */
- msg_data->para_flag |= SRV_SMS_PARA_PID;
- msg_data->para_flag |= SRV_SMS_PARA_SCA;
- msg_data->para_flag |= SRV_SMS_PARA_STATUS;
- msg_data->para_flag |= SRV_SMS_PARA_NUM;
- msg_data->para_flag |= SRV_SMS_PARA_CONTENT;
- msg_data->content_buff = content_ems->textBuffer;
- msg_data->content_buff_size = content_ems->textBufferSize + 2;
- //读取短信内容 在回调函数显示
- srv_sms_read_msg(
- msg_id,
- MMI_FALSE,
- msg_data,
- callback_func,
- NULL);
- }
- void mmi_sample_read_func(srv_sms_callback_struct* callback_data)
- {
- srv_sms_read_msg_cb_struct *read_msg_cb_data;
- srv_sms_msg_data_struct *msg_data;
- //得到短信信息结构体
- read_msg_cb_data =(srv_sms_read_msg_cb_struct*)callback_data->action_data;
- msg_data = read_msg_cb_data->msg_data;
- if (callback_data->result == MMI_TRUE) //读取成功
- {
- newmobi_trace("SMS"," read sms succeed !!!");
- //短信号码
- mmi_chset_ucs2_to_text_str(pOutBuffer,mmi_ucs2strlen(msg_data->number) * 2,msg_data->number,GB2312_ENCODING_TYPE);
- newmobi_trace("pOutBuffer "," == %s",pOutBuffer);
- //短信内容
- mmi_chset_ucs2_to_text_str(pOutBuffer,mmi_ucs2strlen(msg_data->content_buff) * 2,msg_data->content_buff,GB2312_ENCODING_TYPE);
- newmobi_trace("pOutBuffer "," == %s",pOutBuffer);
- }
- else
- {
- newmobi_trace("SMS"," read sms fail !!!");
- }
- }
复制代码 使用方法:
在需要读取短信地方调用下面函数,第1个传参是短信索引,收件箱第一条短信就是索引0,第2个传参是一个函数指针,读取结果将会在mmi_sample_read_func函数中得到
- mmi_read_sms(0,mmi_sample_read_func)
复制代码
|
|
|
|
|
|
|
登录或注册
|