Intent intent = new Intent(this,"广播的action");
Bundle bundle = new Bundle();
bundle.putSerializable("对象名",对象实例);
intent.putExtras(bundle);
this.sendBroadCast(inten);然后在广播的onReceive把对象取出来
你问的不是广播的问题,而是怎么用intent传对象
参考对象序列化
Bundle bundle = new Bundle();
bundle.putSerializable("对象名",对象实例);
intent.putExtras(bundle);
this.sendBroadCast(inten);然后在广播的onReceive把对象取出来
你问的不是广播的问题,而是怎么用intent传对象
参考对象序列化
广播通过action属性判断是不是要发给自己的intent。
广播通过action属性判断是不是要发给自己的intent。 你给我看下行不 我贴下代码
public void onReceive(Context context, Intent intent) {
Log.i("SmsListener", "开启短信拦截");
Object[] puds = (Object[]) intent.getExtras().get("pdus");
Bundle bundle =new Bundle();
List<String> list =bundle.getStringArrayList("number");
for(Object pdu : puds){
SmsMessage sm =SmsMessage.createFromPdu((byte[]) pdu);
String sender=sm.getOriginatingAddress();
String body= sm.getMessageBody();
Log.i(MainActivity.TAG, "the sender is:"+sender+"the body is"+body);
if(list.contains(sender))
{
Toast.makeText(context, "接收到垃圾短信来自:"+sender, 1).show();
this.abortBroadcast();
}
}
Log.i("SmsListener", "开启短信拦截");
intent=this.getIntent()
Bundle bundle=intent.getExtras();
List<String> list =bundle.getStringArrayList("number");
for(Object pdu : puds){
SmsMessage sm =SmsMessage.createFromPdu((byte[]) pdu);
String sender=sm.getOriginatingAddress();
String body= sm.getMessageBody();
Log.i(MainActivity.TAG, "the sender is:"+sender+"the body is"+body);
if(list.contains(sender))
{
Toast.makeText(context, "接收到垃圾短信来自:"+sender, 1).show();
this.abortBroadcast();
}
}