2012-01-11 78 views
0

我正在开发与通过广播接收器接收消息有关的代码。如何将消息存储在从广播接收器接收的列表中

基于休耕代码

@Override 
    public void onReceive(Context context, Intent intent) 
    { 
     //---get the SMS message passed in--- 
     Bundle bundle = intent.getExtras();   
     SmsMessage[] msgs = null; 
     String str = "";    
     if (bundle != null) 
     { 
      //---retrieve the SMS message received--- 
      Object[] pdus = (Object[]) bundle.get("pdus"); 
      msgs = new SmsMessage[pdus.length];    
      for (int i=0; i<msgs.length; i++){ 
       msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);     
       str += "SMS from " + msgs[i].getOriginatingAddress();      
       str += " :"; 
       str += msgs[i].getMessageBody().toString(); 
       str += "\n";   
      } 
      //---display the new SMS message--- 
      Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); 
     }  

我想存储所有的i在列表中接收到的消息和

显示所接收的消息时,我想以列表格式。

+0

你的问题不清楚,你究竟在哪一部分面临问题? – Nitin 2012-01-11 05:52:59

+0

在烤面包中显示正在收到的消息。我想将该消息存储在列表中。并进行修改。 – kiran 2012-01-11 05:55:19

+0

是能够显示它的吐司/ – Nitin 2012-01-11 05:56:54

回答

0

有两种可能的方法:将其存储在数据库或文件中。我认为,更好的方法是使用SQLite。 Here是docs如何创建简单的数据库,存储值并在必要时接收它。还有文档如何读取和写入文件。