Android 学习笔记--android――Notification
android Notification
是显示在手机状态栏上的通知,具有全局效果的通知
时效性不强
步骤:
// 获得系统服务
NotificationManager mNotificationManager
= (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
// 创建一个Notification对象
Notification notification = new Notification(R.drawable.ic_launcher,
"短信来了", System.currentTimeMillis());
// 设置点击事件关联activity
Intent intent = new Intent(this, SecondActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent, 0);
// 设置标题跟内容
notification.setLatestEventInfo(this, "小丽", "在么", contentIntent);
// 发送通知
mNotificationManager.notify(0, notification);
// 点击之后,消失
// notification.flags = Notification.FLAG_AUTO_CANCEL;
// 点击之后,不会消失
notification.flags = Notification.FLAG_ONGOING_EVENT;
取消通知:
mNotificationManager.cancel(0);//参数必须是之前发送通知的id
更多相关文章
- android 上 webkit js 扩展之全局本地对象实现步骤
- Android推送通知指南
- 推送功能,(服务器向android客户端推送信息,通知显示在应用栏)(2018-0
- Android不依赖Activity的全局悬浮窗实现
- Android Wear Preview- 从通知上接收语音输入(Receiving Voice In
- Android Wear Preview- 为通知添加多个页面(Adding Pages to a No
- Android通知栏消息(基本文字通知)
- Android通知Notification学习 及 无法通知解决方案