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. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
  2. android 程序截图功能
  3. Android之省市县三级联动
  4. Android(安卓)ViewPager实现图片 小圆点切换
  5. Android中GPS/Map的运用
  6. Android获取View位置
  7. android 怎样用代码设置墙纸
  8. android dialog
  9. Android(安卓)通知栏Notification 悬浮通知栏

随机推荐

  1. 最全面的Android(安卓)Studio使用教程(图
  2. adb wifi连接手机
  3. Android学习一之环境搭建
  4. layout 布局
  5. 在Eclipse中设置Android模拟器屏幕大小
  6. Android(安卓)高通4.4.4 源码 如何屏蔽Ho
  7. android不同分辨率屏幕横向固定适配
  8. Java(Android)开发人员最常犯的10个错误
  9. android view只能在主线程操作
  10. Android(安卓)NDK开发起步Hello Jni