Android中添加常驻通知栏
2015-10-10 17:47
501 查看
直接看代码吧,很简单的小功能,核心代码就是设置notification的flags为Notification.FLAG_ONGOING_EVENT。
// 添加常驻通知
private void setNotification() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
getString(R.string.app_name), System.currentTimeMillis());
Intent intent = new Intent(this, Rcp_birthdayActivity.class);
notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻 Flag
PendingIntent contextIntent = PendingIntent.getActivity(this, 0,
intent, 0);
notification.setLatestEventInfo(getApplicationContext(),
getString(R.string.app_name), "点击查看", contextIntent);
notificationManager.notify(R.string.app_name, notification);
}
// 取消通知
private void cancelNotification() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(R.string.app_name);
}
// 添加常驻通知
private void setNotification() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
getString(R.string.app_name), System.currentTimeMillis());
Intent intent = new Intent(this, Rcp_birthdayActivity.class);
notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻 Flag
PendingIntent contextIntent = PendingIntent.getActivity(this, 0,
intent, 0);
notification.setLatestEventInfo(getApplicationContext(),
getString(R.string.app_name), "点击查看", contextIntent);
notificationManager.notify(R.string.app_name, notification);
}
// 取消通知
private void cancelNotification() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(R.string.app_name);
}
相关文章推荐
- Android开源项目
- android 开发中的文件操作
- AndroidSwipeLayout:最强大的 Swipe Layout
- Android - 文件读写操作 总结
- 如何做 Android 应用流量测试
- 仿Android QQ左侧滑菜单右侧滑列表菜单——处理HorizontalScrollView和SwipeMenuListView滑动冲突
- Android 监听程序的安装和卸载
- Android ImageView加载摄像头拍摄的大图
- Android中使用lambda表达式
- Android Studio 安装以及使用中遇到的问题
- Android消息推送完美解决方案全析
- Android基础入门教程——8.1.2 Android中的13种Drawable
- Android编程中避免内存泄露的方法总结
- Android Notification几个特殊的视图
- Android中Handler引起的内存泄露
- android数据库的基本简单操作
- Android类-Service - ADIL
- android弹出对话框
- 开发过程中自己遇到的异常(一)
- Android应用截图方法