【问题标题】:Reading only specific SMS messages?只阅读特定的短信?
【发布时间】:2011-09-12 13:58:57
【问题描述】:

我有一个 SMS 接收器,它可以监听传入的 SMS 消息并将 SMS 中的文本保存到 sdcard 上的文件中。我想收听所有传入的消息,但只有特定的消息,以单词“Nemas”或“Preostalo”开头的消息被复制到文本文件中。我该怎么做??

其次,在我处理完特定的消息后,将文本复制到 sdcard 上的文本文件中,我可以自动将此短信从未读设置为已读吗??

【问题讨论】:

标签: android sms broadcastreceiver string-comparison


【解决方案1】:

对于 SMS 写入文件,将消息内容作为正文存储到 String 对象中。现在检查这是否以“Nemas”或“Preostalo”开头,然后写入txt文件。

private static final String NEMAS = "Nemas";
private static final String PREOSTALO = "Preostalo";

private String msg;

在第一次获取消息时检查消息并存储到 msg 对象中

if(msg.startsWith(NEMAS) || msg.startsWith(PREOSTALO)){

     // write the msg into the txt file

}

【讨论】:

  • startWith() 给出错误,并让我更改为 startsWith () ??可以吗??
  • 对不起,这是开头我忘记了这里的“s”
猜你喜欢
  • 2010-10-28
  • 1970-01-01
  • 2013-04-17
  • 2018-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-23
  • 1970-01-01
相关资源
最近更新 更多