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

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

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/19
下载{$ArticleTitle}原创论文样式
  private Context context;    @Override  public void onReceive(Context context, Intent intent) {  this.context = context;  deleteNotification();  }    private void deleteNotification() {  NotificationManager notificationManager = (NotificationManager) context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);  notificationManager.cancel(Receiver1.NOTIFICATION_ID);  }  }      public class Receiver2 extends BroadcastReceiver {  private Context context;  @Override  public void onReceive(Context context, Intent intent) {  this.context = context;  deleteNotification();  }  private void deleteNotification() {  NotificationManager notificationManager = (NotificationManager) context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);  notificationManager.cancel(Receiver1.NOTIFICATION_ID);  }  } Java代码    public class MainActivity extends Activity {  private final String ACTION_SEND = "com.forrest.action.SENDMESSAGE",  ACTION_CLEAR = "com.forrest.action.CLEARNOTIFICATION";    public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.main);  ( (Button) findViewById(R.id.btn1) ).setOnClickListener(new OnClickListener() {  public void onClick(View v) {  clickMenuItem(ACTION_SEND);  }  });  ( (Button) findViewById(R.id.btn2) ).setOnClickListener(new OnClickListener() {  public void onClick(View v) {  clickMenuItem(ACTION_CLEAR);  }  });  }    private void clickMenuItem(final String action) {  Intent intent = new Intent(action);  sendBroadcast(intent);  }  }      public class MainActivity extends Activity {  private final String ACTION_SEND = "com.forrest.action.SENDMESSAGE",  ACTION_CLEAR = "com.forrest.action.CLEARNOTIFICATION";  public void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.main);  ( (Button) findViewById(R.id.btn1) ).setOnClickListener(new OnClickListener() {  public void onClick(View v) {  clickMenuItem(ACTION_SEND);  }  });  ( (Button) findViewById(R.id.btn2) ).setOnClickListener(new OnClickListener() {  public void onClick(View v) {  clickMenuItem(ACTION_CLEAR);  }  });  }  private void clickMenuItem(final String action) {  Intent intent = new Intent(action);  sendBroadcast(intent);  }  } 注册Broadcast Reciver Xml代码    <application android:ic

网学推荐

免费论文

原创论文

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