错误读取文本短信的详细信息? [英] Error in fetching text sms details?

查看:182
本文介绍了错误读取文本短信的详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建这个帖子得到帮助。我正在开发它发送一个应用程序传入的文本短信。什么我做的是获取传入的消息体,日期和时间并将其作为新的消息。发送目的我使用短信管理器
我能够获得多个消息体使用复选框并创建一个列表选定的消息。但问题是在得到他们的日期和时间。

code的主要活动:

 字符串身体=;
ArrayAdapter< SMSListModel>适配器;
清单< SMSListModel>名单=新的ArrayList< SMSListModel>();

code选定的消息数组列表:

 私人列表< SMSListModel> getModel()
{
    如果(cursor.getCount()大于0)
    {
        的for(int i = 0; I< cursor.getCount();我++)
        {
            如果(cursor.moveToPosition(i))的
            {
                list.add(新SMSListModel(cursor.getString(cursor.getColumnIndex(\"address\")),cursor.getString(cursor.getColumnIndex(\"body\"))));
            }
        }
    }
    返回列表;
}

code为SMSListModel

 公共SMSListModel(字符串的地址,字符串体){
    this.address =地址;
    this.body =身体;
}
公共布尔isSelected(){
    返回所选择的;
}公共无效的setSelected(布尔选择){
    this.selected =选择;
}

code发送所选邮件​​正文:

 如果(则为list.size()0){
       的for(int i = 0; I<则为list.size();我++)
       {
           如果(list.get(ⅰ).isSelected())
           {
            如果(body.equals())
                   体= list.get(ⅰ).getBody();               其他
                体= list.get(ⅰ).getBody();
             尝试
             {
                 字符串mbody =从+DD / MM / YY+HH:MM+体;
                 SmsManager smsManager = SmsManager.getDefault();
                 smsManager.sendTextMessage(PHONENO,空,mbody,NULL,NULL);
             }
             赶上(例外五)
             {
                 //发生错误,如果没有消息选择
                    e.printStackTrace();
             }


解决方案

几code尽管如此zmissing的朋友,但同时,我们可以修复code,你张贴,给你方向,现有的,哪些是你我以前不张贴在这里..

首先修改code为SMSListModel

 公共类SMSListModel {    字符串日期;
    字符串的时间;
    字符串的地址;
    绳体;    公共SMSListModel(地址字符串,字符串的身体,时间字符串,字符串日期){
        this.address =地址;
        this.body =身体;
        this.time =时间;
        this.date =日期;
    }    公共字符串的getAddress(){
        退货地址;
    }    公共无效setAddress(字符串地址){
        this.address =地址;
    }    公共字符串GETDATE(){
        归期;
    }    公共无效的setDate(字符串日期){
        this.date =日期;
    }    公共字符串的getTime(){
        返回时间;
    }    公共无效的setTime(字符串时间){
        this.time =时间;
    }    公共字符串getBody(){
        回体;
    }    公共无效setBody(字符串体){
        this.body =身体;
    }
    公共布尔isSelected(){
           返回所选择的;
    }
    公共无效的setSelected(布尔选择){
    this.selected =选择;
    }}

更改更新code选定的消息数组列表:

 私人列表< SMSListModel> getModel()
{
    如果(cursor.getCount()大于0)
    {
        的for(int i = 0; I< cursor.getCount();我++)
        {
            如果(cursor.moveToPosition(i))的
            {
                list.add(新SMSListModel(cursor.getString(cursor.getColumnIndex(\"address\")),cursor.getString(cursor.getColumnIndex(\"body\"))),cursor.getColumnIndex(\"time\")) ,cursor.getColumnIndex(DATE)));
            }
        }
    }
    返回列表;
}

注:对于cursor.getColumnIndex(时代))和cursor.getColumnIndex(DATE))首先你需要在你的数据库类来创建两个柱名时间,日期,也为插入值当短信接收。

code发送所选消息体

 如果(则为list.size()0){
       的for(int i = 0; I<则为list.size();我++)
       {
           如果(list.get(ⅰ).isSelected())
           {
            如果(body.equals())
                   体= list.get(ⅰ).getBody();
                   日期= list.get(I).getDate();
                   时间= list.get(ⅰ).getTime();               其他
                体= list.get(ⅰ).getBody();
                日期= list.get(I).getDate();
                时间= list.get(ⅰ).getTime();
             尝试
             {
                 字符串mbody =从+日期+时间+体;
                 SmsManager smsManager = SmsManager.getDefault();
                 smsManager.sendTextMessage(PHONENO,空,mbody,NULL,NULL);
             }
             赶上(例外五)
             {
                 //发生错误,如果没有消息选择
                    e.printStackTrace();
             }

**注:您需要修改您的数据库。对于修改表并在末尾添加两列的时间和日期。

之后,你还需要改变你的BroadcastReceiver子类的code这收到消息,该消息存储到数据库中。从该类还需要输入日期和时间价值,你的表。**

I'm creating this post to get help. I am developing an application which sends incoming text sms.What I'm doing is fetching incoming message body, date and time and send it as new message. for sending purpose I'm using sms manager. I'm able to get multiple message body using checkboxes and creating a list of selected messages. But the problem is in getting their date and time.

Code in main Activity:

String body="";
ArrayAdapter<SMSListModel> adapter;
List<SMSListModel> list = new ArrayList<SMSListModel>();

Code for array list of selected messages:

 private List<SMSListModel> getModel() 
{
    if(cursor.getCount()>0)
    {
        for(int i=0;i<cursor.getCount();i++)
        {
            if(cursor.moveToPosition(i))
            {
                list.add(new SMSListModel(cursor.getString(cursor.getColumnIndex("address")),cursor.getString(cursor.getColumnIndex("body"))));
            }
        }
    }
    return list;
}

Code for SMSListModel

  public SMSListModel(String address, String body) {
    this.address = address;
    this.body = body;
}
public boolean isSelected() {
    return selected;
}

public void setSelected(boolean selected) {
    this.selected = selected;
}

Code to send selected message body:

if(list.size()>0){
       for(int i=0;i<list.size();i++)
       {
           if(list.get(i).isSelected())
           {
            if(body.equals(""))
                   body =list.get(i).getBody();

               else
                body =list.get(i).getBody();
             try
             {
                 String mbody = "from"+ "dd/mm/yy" +"hh:mm"+body;
                 SmsManager smsManager = SmsManager.getDefault();
                 smsManager.sendTextMessage(phoneNo, null, mbody, null, null);
             }                           
             catch (Exception e)
             {
                 //Error Occurred if No Messages Selected 
                    e.printStackTrace();
             }

解决方案

few code Still zmissing friend but well we can fix code which you post and give you direction for existing one and which you did't post here..

First modify Code for SMSListModel

public class SMSListModel {

    String date;
    String time;
    String address;
    String body;

    public SMSListModel(String address, String body, String time, String date) {
        this.address = address;
        this.body = body;
        this.time = time;
        this.date = date;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }
    public boolean isSelected() {
           return selected;
    }
    public void setSelected(boolean selected) {
    this.selected = selected;
    }

}

Change update Code for array list of selected messages:

private List<SMSListModel> getModel() 
{
    if(cursor.getCount()>0)
    {
        for(int i=0;i<cursor.getCount();i++)
        {
            if(cursor.moveToPosition(i))
            {
                list.add(new SMSListModel(cursor.getString(cursor.getColumnIndex("address")),cursor.getString(cursor.getColumnIndex("body"))),cursor.getColumnIndex("time")) , cursor.getColumnIndex("date")) );
            }
        }
    }
    return list;
}

NOTE : For cursor.getColumnIndex("time")) and cursor.getColumnIndex("date")) first you need to create two column with name time,date in your database class and also insert value for that when sms receive.

Code to send selected message body

if(list.size()>0){
       for(int i=0;i<list.size();i++)
       {
           if(list.get(i).isSelected())
           {
            if(body.equals(""))
                   body =list.get(i).getBody();
                   date =list.get(i).getDate();
                   time =list.get(i).getTime();

               else
                body =list.get(i).getBody();
                date =list.get(i).getDate();
                time =list.get(i).getTime();
             try
             {
                 String mbody = "from"+ date + time +body;
                 SmsManager smsManager = SmsManager.getDefault();
                 smsManager.sendTextMessage(phoneNo, null, mbody, null, null);
             }                           
             catch (Exception e)
             {
                 //Error Occurred if No Messages Selected 
                    e.printStackTrace();
             }

**Note: You need to modify your database. for that modify table and add two column at end "time" and "date".

after that you also need to change your broadcastReceiver subclass's code which receive message and store this message into database. from that class you also need to enter time and date value to your table.**

这篇关于错误读取文本短信的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆