android短信获取小代码

Bundle bdl = intent.getExtras();  
try {  
    Object pdus[] = (Object [])bdl.get("pdus");  
    for(int i=0; i < pdus.length; i++) {  
        byte[] data = (byte[])pdus[i];  
        SmsMessage msg = SmsMessage.createFromPdu(data);  
          
        if(msg.getMessageBody().equals(Sample.FireMessage)) {  
            //rock here  
            Intent start = new Intent(Sample.StartMusicAction);  
              
            start.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
            //start.setAction(StartMusicAction);  
            context.startActivity(start);  
        }  
    }  
}  
catch(Exception e) {  
    Log.e("GetMessage", "fail", e);  

你可能感兴趣的:(android)