package com.notification.tools;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import com.notification.activity.R;
/**
* @author 彭文忠
* @discribe 如果系统没有运行在最前方,则我们让程序显示在通知栏
*/
public class NotificationShow {
/**
* @author 彭文忠、陈位斌
* @discribe 让程序在通知栏
* @param context 需要最小化到通知栏的上下文(Activity.this)
* @param cls 点击通知栏返回的地方
*/
public static void showNotification(Context context,Class<?> cls) {
// 创建一个NotificationManager对象
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
// 定义notification的各种属性
Notification notification = new Notification(/*
* R.drawable.qq, "手机QQ",
* System
* .currentTimeMillis()
*/);
notification.icon = R.drawable.qq;
// 如果设置了下面的这句,则通知栏一开始会占满,
// notification.tickerText="手机QQ";
notification.flags |= Notification.FLAG_ONGOING_EVENT; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中
notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults = Notification.DEFAULT_LIGHTS;
notification.ledARGB = Color.BLUE;
notification.ledOnMS = 5000;
// 设置通知的事件消息
CharSequence contentTitle = "流年(在线)"; // 通知栏标题
CharSequence contentText = "最新版本号2012.3.27"; // 通知栏内容
Intent notificationIntent = new Intent(context, cls); // 点击该通知后要跳转的Activity
PendingIntent contentItent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentItent);
// 把Notification传递给NotificationManager
notificationmanager.notify(0, notification);
}
/**
* @author 彭文忠、陈位斌
* @discribe 用来移除某个项目残留在通知栏的通知的
* @param context
* 需要移除通知的上下文(即Acitivity.this)
*/
public static void removeNotification(Context context) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(0);
}
}
NotificationDemo,类似QQ图标实现,
4星 · 超过85%的资源 需积分: 9 138 浏览量
2012-03-30
17:08:32
上传
评论 2
收藏 88KB RAR 举报
awen_PC
- 粉丝: 27
- 资源: 42
最新资源
- 筷手引流工具.apk
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页