听和reciveing特定的短信? [英] Listening and reciveing specific SMS message?
问题描述
好吧,我有听来电短信这个广播reciver
Ok i Have this broadcast reciver for Listening incoming SMS
public class SmsReceiver extends BroadcastReceiver
{
@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 += msgs[i].getMessageBody().toString();
}
}
try {
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()){
File dir = new File (root.getAbsolutePath() + "/Bonbon info");
dir.mkdirs();
File f = new File(dir, "test.txt");
FileWriter fw = new FileWriter(f);
BufferedWriter out = new BufferedWriter(fw);
out.write(str);
out.close();
}
} catch (IOException e) {
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_LONG).show();
}
}
现在,我需要倾听只有特定的短信,有单词Nemas或Potrosio在SMS.Can的第一个字,你帮我这个????
Now, i need to listen only specific SMS messages, that have word "Nemas" or "Potrosio" for the first word in the SMS.Can you help me with this ????
编辑:我犯了一个错误,我也没有问正确的问题。我想recive所有消息,但只能用特定的文本短信我需要保存成文本文件?
I made a mistake, and i didn't ask a right question. I want to recive ALL messages, but only SMS with specific text I need to save into text file ?
推荐答案
<一个href=\"http://stackoverflow.com/questions/4851295/android-receiving-sms-from-specific-phone-number\">Android:接收来自特定的电话号码的短信
http://www.androidcompetencycenter.com/2008/12 / Android的API-SMS-处理/
http://www.anddev.org/recognize-react_on_incoming_sms-t295.html
这篇关于听和reciveing特定的短信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!