android学习笔记---发送状态栏通知

发送消息的代码如下:    

复制代码
//获取通知管理器     
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);     
    int icon = android.R.drawable.stat_notify_chat;     
    long when = System.currentTimeMillis();     
    //新建一个通知,指定其图标和标题     
Notification notification = new Notification(icon, null, when);//第一个参数为图标,第二个参数为标题,第三个为通知时间     
notification.defaults = Notification.DEFAULT_SOUND;//发出默认声音     
Intent openintent = new Intent(this, OtherActivity.class);     
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, openintent, 0);//当点击消息时就会向系统发送openintent意图     
notification.setLatestEventInfo(this, “标题”, “我是内容", contentIntent);     
    mNotificationManager.notify(0, notification);//第一个参数为自定义的通知唯一标识    
复制代码


 

摘自 http://www.tuicool.com/articles/MjuUzi

posted @   iDEAAM  阅读(916)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
历史上的今天:
2013-08-13 解决 Provider 'System.Data.SqlServerCe.3.5' not installed. -摘自网络
点击右上角即可分享
微信分享提示