当前位置: 网学 > 编程文档 > Android > 正文

Broadcast Receiver接收并处理自定义Action广播通知

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/19
下载{$ArticleTitle}原创论文样式
gt;  <intent-filter>  <!-- 和Intent中的action对应 -->  <action android:name="com.forrest.action.mybroadcast"/>  </intent-filter>  </receiver> 2)在代码中注册 Java代码    IntentFilter filter = new IntentFilter("com.forrest.action.mybroadcast"); // 和广播中Intent的action对应  MyBroadcastReceiver br = new MyBroadcastReceiver();  registerReceiver(new MyBroadcastReceiver(), filter);      IntentFilter filter = new IntentFilter("com.forrest.action.mybroadcast"); // 和广播中Intent的action对应  MyBroadcastReceiver br = new MyBroadcastReceiver();  registerReceiver(new MyBroadcastReceiver(), filter); 3)注销 Java代码    unregisterReceiver(br);      unregisterReceiver(br);   3. 示例代码 Java代码    public class Receiver1 extends BroadcastReceiver {  private Context context;  public static final int NOTIFICATION_ID = 10001;    public void onReceive(Context context, Intent intent) {  this.context = context;  showNotification();  }    private void showNotification() {  Notification notification = new Notification(R.drawable.icon, "来电话啦", System.currentTimeMillis());  PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);  notification.setLatestEventInfo(context, "来电话啦嘿嘿", "赶紧接电话,否则误大事了", contentIntent);    NotificationManager notificationManager = (NotificationManager) context.getSystemService(  android.content.Context.NOTIFICATION_SERVICE);  notificationManager.notify(NOTIFICATION_ID, notification);  }  }      public class Receiver1 extends BroadcastReceiver {  private Context context;  public static final int NOTIFICATION_ID = 10001;  public void onReceive(Context context, Intent intent) {  this.context = context;  showNotification();  }  private void showNotification() {  Notification notification = new Notification(R.drawable.icon, "来电话啦", System.currentTimeMillis());  PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);  notification.setLatestEventInfo(context, "来电话啦嘿嘿", "赶紧接电话,否则误大事了", contentIntent);  NotificationManager notificationManager = (NotificationManager) context.getSystemService(  android.content.Context.NOTIFICATION_SERVICE);  notificationManager.notify(NOTIFICATION_ID, notification);  }  } Java代码    public class Receiver2 extends BroadcastReceiver {

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号