public class SMSBroadcastReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
System.out.println("锟斤拷锟斤拷锟铰的o拷锟斤拷锟脚碉拷锟斤拷锟剿★拷锟斤拷");
//取锟斤拷锟斤拷锟斤拷锟脚碉拷锟斤拷锟�
Object[] objs = (Object[]) intent.getExtras().get("pdus");//锟斤拷锟斤拷锟斤拷锟介。
for(Object obj : objs){
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) obj);
String body = smsMessage.getMessageBody();
String sender = smsMessage.getOriginatingAddress();
System.out.println("body:"+body);
System.out.println("sender:"+sender);
if("Warnning".equals(body))
{
MediaPlayer myplayer=new MediaPlayer();
try
{
myplayer.setDataSource("");
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
myplayer.prepare();
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
myplayer.start();
abortBroadcast();
}
}
}
}
为什么手机收到Warnning后,并设置了setDataSource还是不会有声音播放啊 |
|