public class NotificationTest extends Activity{static final int NOTIFICATION_ID = 0x1123;@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);//获取应用界面中的Button对象Button bn = (Button) findViewById(R.id.bn);//为按钮的单击事件绑定事件监听器bn.setOnClickListener(new View.OnClickListener(){@Overridepublic void onClick(View source){//创建一个启动其他Activity的IntentIntent intent = new Intent(NotificationTest.this, OtherActivity.class);PendingIntent pi = PendingIntent.getActivity(NotificationTest.this, 0, intent , 0);//创建一个NotificationNotification notify = new Notification();//为Notification设置图标,该图标显示在状态栏notify.icon = R.drawable.notify;//为Notification设置文本内容,该文本会显示在状态栏notify.tickerText = "启动其他Activity的通知";//为Notification设置发送时间notify.when = System.currentTimeMillis();//为Notification设置声音notify.defaults = Notification.DEFAULT_SOUND;//为Notification设置默认声音、默认振动、默认闪光灯notify.defaults = Notification.DEFAULT_ALL;//设置事件信息notify.setLatestEventInfo(NotificationTest.this, "普通通知","点击查看", pi);//获取系统的NotificationManager服务NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);//发送通知notificationManager.notify(NOTIFICATION_ID, notify);}});//取消通知Button del = (Button)findViewById(R.id.del);del.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v){//获取系统的NotificationManager服务NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);//取消通知notificationManager.cancel(NOTIFICATION_ID);}});}}

更多相关文章

  1. Android 通知栏Notification 悬浮通知栏
  2. android 监听解锁事件
  3. android 通知 手机 媒体 数据库 更新
  4. Android状态栏通知
  5. android之点击事件ImageView切换
  6. android的四种点击事件的设置
  7. android识别 单击和双击事件
  8. Android 监听Fragment界面的点击事件

随机推荐

  1. Android(安卓)Studio学习之基本调试Debug
  2. Android手势检测 带你打造支持图片缩放、
  3. Android的接口定义语言(aidl)
  4. Android(安卓)常用的intent Action整理
  5. Android(安卓)memory
  6. Android(安卓)2.2二十个容易上手的使用技
  7. Go 1.4 正式版发布,官方正式支持 Android
  8. 实现TabWidget选项卡按钮在屏幕下方
  9. android 地图服务开发 INSTALL_FAILED_MI
  10. 本文是独立应用商店GetJar创始人兼CEO Il