android Notification 点击与移除监听
2015-11-02 09:57
363 查看
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()); }
相关文章推荐
- 基础Android应用开发 Button显示系统时间+TextView显示随机数+简单计算器
- Android 自定义组件之 带有悬浮header的listview
- I.MX6 GPS Android HAL Framework 调试
- android notification点击与移除监听
- Android学习路线权威指南
- android studio 使用aar
- android学习
- Android高斯模糊,左右有白边
- 超图---简单地图显示
- Android中DataTime控件的使用(九)
- AndroidStudio权威教程 AS添加第三方库的6种方式(Jar module so等)
- SEAndroid语法介绍
- android studio JNI编程
- Android自定义控件之仿汽车之家下拉刷新
- 修改Launcher2在ADT上编译调试(一)
- Android AndroidManifest 清单文件以及权限详解
- Android ViewTreeObserver简介
- 清除android程序中的多余资源
- 完全解决!android studio更新 check for updates失败的问题
- ACTION_POWER_DISCONNECTED广播使用解析