Notification基本通知的两种写法
来源:互联网 发布:数据保全系统 编辑:程序博客网 时间:2024/05/29 04:48
private void newNotify() { // 1.创建通知的Builder对象 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this); //2.设置参数 对象链式操作 mBuilder.setSmallIcon(R.drawable.ic_launcher); //设置小图标 mBuilder.setContentTitle("hello title"); //设置标题 mBuilder.setContentText("Hello content");//设置内容 //3.创建一个意图对象 Intent resultIntent = new Intent(this, OtherActivity.class); //4.创建TaskStackBuilder对象 TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); //5.添加到stackBuilder对象中 stackBuilder.addParentStack(OtherActivity.class); //6.添加到顶端 stackBuilder.addNextIntent(resultIntent); //7.意图对象 PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); //8.设置意图对象 mBuilder.setContentIntent(resultPendingIntent); // 9.获取NotificationManager对象 NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //10.发送通知 mNotificationManager.notify(mId, mBuilder.build()); } private void oldNotify() { // 1.获取NotificationManager对象 NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // 2.定义通知 Notification notification = new Notification(); // 3.设置参数 notification.icon = R.drawable.ic_launcher; // 设置图标 notification.when = System.currentTimeMillis(); // 发送通知的时间 // 定义意图 Intent intent = new Intent(this, OtherActivity.class); // 意图 :跨进程的意图 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // 设置通知的最新事件消息 notification.setLatestEventInfo(this, "hello title", "hello content", pendingIntent); // 3.发通知 manager.notify(1, notification); }
2 0
- Notification基本通知的两种写法
- Notification通知的基本用法
- Notification--------通知的基本用法
- android Notification显示通知的两种方法
- Android 通知Notification的两种实现方法
- 安卓中通知(Notification)的基本使用方法
- 安卓中通知(Notification)的基本使用方法
- 系统通知Notification的基本用法
- android 通知Notification的基本用法
- 关于Notification通知的基本使用
- Notification通知栏的基本使用
- 通知栏(Notification)的基本使用
- Android 原生通知Notification 写法
- 欧拉函数的两种基本写法
- 通知栏Notification基本使用
- Android之Notification(一):通知的基本用法
- Notification的两种用法
- Notification通知的详解
- [leetcode] Combinations
- jni.h头文件学习笔记
- Android 数字动画
- Android应用层View绘制流程与源码分析
- 初学MFC——加载位图
- Notification基本通知的两种写法
- 分享8年开发经验,浅谈程序员职业规划
- php无法正常发送邮件
- linux命令收集(根据自己需要整理)
- ExpandableListView 实现分组购物车
- Android开发之EditText属性详解
- effective stl
- 印度母亲强奸儿子以矫治同性恋引热议
- 余波:技术人员如何走出职业迷茫