Notifiation通知的一些知识
2015-07-07 19:38
330 查看
通知,即push消息,需要添加icon、defaults、flags;
下面是一些知识点:是通过开启一个定时器,循环判断是否是桌面,是桌面则发送push信息,点击 push,响应一个INTENT_ACTION_VIEW,发送一个url链接到浏览器:
/**
* 开始定时器
*/
private void startTimer() {
if (mTimer == null) {
mTimer = new Timer();
CheckTask lockTask = new CheckTask();
mTimer.schedule(lockTask, 0L, 1000L);
}
}
/**
* 关闭监听服务
*/
public void closeTimer() {
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
}
/**
* 定时器执行任务
*/
public class CheckTask extends TimerTask {
@Override
public void run() {
if (PackageMangerTool.isLauncherRunnig(MainActivity.this)) {
Intent it = new Intent("action.after.out");
showNotifation(getApplicationContext(), title, pic, it);
closeTimer();
MainActivity.this.finish();
}
}
}
@SuppressWarnings("deprecation")
private void showNotifation(Context mContext, String title, String pic,
Intent it) {
//获取NotificationManager
NotificationManager manager = SystemServiceUtils
.getNotificationManager(mContext);
Notification notification = new Notification();
notification.icon = android.R.drawable.ic_dialog_info;// 默认图标
notification.defaults |= Notification.DEFAULT_ALL;// 使用默认闪光提示
notification.flags |= Notification.FLAG_AUTO_CANCEL; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用
//notification.tickerText = "wwq";// 设置标题
notification.flags |= Notification.FLAG_NO_CLEAR;// 不可清除
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
// 获得PendingIntent
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this,push的title,
push的内容, pi);
manager.notify(1, notification);
}
下面是一些知识点:是通过开启一个定时器,循环判断是否是桌面,是桌面则发送push信息,点击 push,响应一个INTENT_ACTION_VIEW,发送一个url链接到浏览器:
/**
* 开始定时器
*/
private void startTimer() {
if (mTimer == null) {
mTimer = new Timer();
CheckTask lockTask = new CheckTask();
mTimer.schedule(lockTask, 0L, 1000L);
}
}
/**
* 关闭监听服务
*/
public void closeTimer() {
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
}
/**
* 定时器执行任务
*/
public class CheckTask extends TimerTask {
@Override
public void run() {
if (PackageMangerTool.isLauncherRunnig(MainActivity.this)) {
Intent it = new Intent("action.after.out");
showNotifation(getApplicationContext(), title, pic, it);
closeTimer();
MainActivity.this.finish();
}
}
}
@SuppressWarnings("deprecation")
private void showNotifation(Context mContext, String title, String pic,
Intent it) {
//获取NotificationManager
NotificationManager manager = SystemServiceUtils
.getNotificationManager(mContext);
Notification notification = new Notification();
notification.icon = android.R.drawable.ic_dialog_info;// 默认图标
notification.defaults |= Notification.DEFAULT_ALL;// 使用默认闪光提示
notification.flags |= Notification.FLAG_AUTO_CANCEL; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用
//notification.tickerText = "wwq";// 设置标题
notification.flags |= Notification.FLAG_NO_CLEAR;// 不可清除
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
// 获得PendingIntent
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this,push的title,
push的内容, pi);
manager.notify(1, notification);
}
相关文章推荐
- 一次单片机最小系统的调试
- VIM 初步
- 初学C语言之结构体
- android studio 使用细节
- SQL_CASE WHEN &临时表 &xml to table 混合实例
- appcan 在子窗口中关闭窗口
- Activity的启动方式和flag详解[刚哥的]
- discuz使用
- leetcode 46 : Permutations
- device not managed by NetworkManager
- LeetCode 232: Implement Queue using Stacks
- stretchableImageWithLeftCapWidth气泡拉伸
- Android各个support library特征和区别(官方文档)
- D的小L
- 82.取出字符串中的数字字符组成新的字符串
- appcan 主窗口调子窗口的方法
- android源码使用proguard混淆编译及错误总结
- linux 下 hadoop ssh协议免登录原理的介绍
- ECNUOJ 2573 Hub Connection plan
- STM32W108无线传感器网络多传感器环境参数监测实例