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传对象
参考对象序列化
解决方案 »
- android 导入外部json包错误,高手帮忙
- 局域网和互联网的通信
- 急!!!! 跪求查找所有包含图片文件(png,jpg,gif,bmp==)的目录
- 问题:使用eclipse开发android源码
- 【急】【急】【急】对android接收消息流程清楚的高手进来看看吧~
- android菜鸟问一下大侠们,在android中怎样使用linux命令
- android手机USB连接电脑发送短信
- listview接受接口数据,点击每个item跳转到对应Activity
- 关于AVD设置
- 求android手机视频监控原码
- 关于自定义EditText,求助!
- Android串口编程时遇到了问题 贴出logcat 帮我看看
广播通过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();
}
}