private void showNotification() {NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);mBuilder.setContentTitle("测试标题")// 设置通知栏标题.setContentText("测试内容")// 设置通知栏显示内容.setContentIntent(getDefalutIntent(Notification.FLAG_AUTO_CANCEL))// 设置通知栏点击意图// .setNumber(number);.setTicker("测试通知来啦")// 通知栏首次出现在通知栏,带上动画效果.setWhen(System.currentTimeMillis())// 通知栏时间,一般是直接用系统的.setPriority(Notification.DEFAULT_ALL)// 设置通知栏优先级.setAutoCancel(true)// 用户单击面板后消失.setOngoing(false)// true,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此// 占用设备(如一个文件下载,同步操作,主动网络连接).setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)// 向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,// 使用default属性,可以组合// Notification.DEFAULT_ALL Notification.DEFAULT_SOUND 添加声音 //// requires VIBRATE permission.setSmallIcon(R.drawable.ic_launcher);Notification notification = mBuilder.build();notification.flags = Notification.FLAG_ONGOING_EVENT;notification.flags = Notification.FLAG_NO_CLEAR;// 点击清除的时候不清除//Intent realIntent = new Intent(getApplicationContext(), MainActivity.class);//realIntent.addCategory(Intent.CATEGORY_LAUNCHER);//realIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);Intent clickIntent = new Intent("action_click",null,getApplicationContext(), NotificationReceiver.class);//clickIntent.setAction("action_click");Intent dismissIntent = new Intent("action_dismiss", null, getApplicationContext(), NotificationReceiver.class);//intent.putExtra("realIntent", realIntent);//PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent,//0);PendingIntent clickPendingIntent = PendingIntent.getBroadcast(this, 0, clickIntent,0);PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(this, 0, dismissIntent,0);mBuilder.setContentIntent(clickPendingIntent);mBuilder.setDeleteIntent(dismissPendingIntent);mNotificationManager.notify(0, mBuilder.build());}

更多相关文章

  1. Android(安卓)ExpandableListView 可展开的ListView
  2. Android通过Mainfest设置Theme实现布局全屏
  3. Android推送通知
  4. Android日历
  5. Android(安卓)Random随机数
  6. 【android】读取通讯录
  7. Android之UI学习篇一:TextVeiw如何显示丰富的文本
  8. android:layout_marginLeft指该控件距离边父控件的边距, android:
  9. Android(安卓)Studio系列教程二--基本设置与运行

随机推荐

  1. MySQL教程子查询示例详解
  2. MySQL数据分析存储引擎示例讲解
  3. MySQL系列数据库设计三范式教程示例
  4. 详细聊聊MySQL中的LIMIT语句
  5. MySQL系列理解运用union(all)与limit及ex
  6. MySQL教程彻底学懂存储过程
  7. MySQL内部临时表的具体使用
  8. 浅谈Mysql在什么情况下会使用内部临时表
  9. Android: Android图形基础
  10. 转 Android中shape中的属性大全