Android 如何阅读收到的短信

Android 如何阅读收到的短信,android,Android,可能重复: 我想阅读传入的短信,以检查短信中是否存在特定值 我找到了这个短信接收码 我想检查接收sms是否有以下值xml值 请帮我检查一下 //this is response which i check in reciving sms 00 LOG 00 Adeel Aslam 10.00 10/05/2012 10:00 +100 //this is code which i found for sms recive public class SmsReceiver ext

可能重复:

我想阅读传入的短信,以检查短信中是否存在特定值

我找到了这个短信接收码 我想检查接收sms是否有以下值xml值

请帮我检查一下

//this is response which i check in reciving sms

00
LOG
00
Adeel Aslam
10.00
10/05/2012 10:00
+100


//this is code which i found for sms recive
     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 += "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();
    }   

} 
//这是我在接收短信时签入的响应
00
日志
00
阿德尔·阿斯拉姆
10
10/05/2012 10:00
+100
//这是我为短信接收找到的代码
公共类SmsReceiver扩展了BroadcastReceiver
{
@凌驾
公共void onReceive(上下文、意图)
{
//---获取传入的SMS消息---
Bundle=intent.getExtras();
SmsMessage[]msgs=null;
字符串str=“”;
if(bundle!=null)
{
//---检索收到的SMS消息---
Object[]pdus=(Object[])bundle.get(“pdus”);
msgs=新SMS消息[PDU.length];
对于(int i=0;i您可以使用
contains()
方法检查sms中是否存在特定的单词

 if(str.contains("LOG"))
  {
    // Perform your task here.
   }

但是我想检查短信是否有特别的价值,不仅仅是阅读我是如何检查的?有什么区别?你阅读一条短信来检查其中包含的数据。str.contains(“LOG”)因此,在这个代码日志中有一个特定的词?
Log
是您要在传入的sms中检查的值。您可以将其放入任何内容。如果收到特定的sms,如何启动新活动?只需使用
切换案例
,如果它满足条件/案例,则启动相应的活动。:)我使用了这个if(str.contains(“00”)){Intent k=new Intent(this.getApplicationContext(),AgAppMenu.class);startActivity(k);}但显示错误