Intent intent = new Intent(this,"广播的action");
Bundle bundle = new Bundle();
bundle.putSerializable("对象名",对象实例);
 intent.putExtras(bundle);
this.sendBroadCast(inten);然后在广播的onReceive把对象取出来
你问的不是广播的问题,而是怎么用intent传对象
参考对象序列化

解决方案 »

  1.   

     那我这个intent 传过去的值,是在所有的broadcastReceiver 都能取到吗?需不需要把这个activity 和我的目的broadcast 关联呢
      

  2.   

     那我这个intent 传过去的值,是在所有的broadcastReceiver 都能取到吗?需不需要把这个activity 和我的目的broadcast 关联呢你发intent的时候会隐式指定这个intent目标组件的action属性啊,这个action属性当然要在你注册广播的时候绑定到你的广播了。这样你发intent,就会被你指定action的组件接收,然后在广播的onreceive处理这个intent中附带的信息。
    广播通过action属性判断是不是要发给自己的intent。
      

  3.   

     那我这个intent 传过去的值,是在所有的broadcastReceiver 都能取到吗?需不需要把这个activity 和我的目的broadcast 关联呢你发intent的时候会隐式指定这个intent目标组件的action属性啊,这个action属性当然要在你注册广播的时候绑定到你的广播了。这样你发intent,就会被你指定action的组件接收,然后在广播的onreceive处理这个intent中附带的信息。
    广播通过action属性判断是不是要发给自己的intent。 你给我看下行不 我贴下代码
      

  4.   

    这是广播里面的处理
    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();
    }

    }
      

  5.   

    你是这里写错了吧public void onReceive(Context context, Intent intent) {
             
            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();
                }
         
            }