1. Notification构造器的参数
分别为:在状态条上显示的图标、文字和Notification的当前时间
// Choose a drawable to display as the status bar icon
int icon = R.drawable.icon;
// Text to display in the status bar when the notification is launched
String tickerText = “Notification”;
// The extended status bar orders notification in time order
// Notification显示的时间, currentTimeMills表示立即显示
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
2. setLatestEventInfo()用来配置Notification在扩展的状态窗口中的外观
。扩展的状态窗口将显示图标和在构造函数中传入的时间,以及显示Notification标题和Notification内容。Notification可通过指定PendingIntent来触发。
Context context = getApplicationContext();
// Text to display in the extended status window
String expandedText = “Notification Text”;
// Title for the expanded status
String expandedTitle = “Notification Title”;
// Intent to launch an activity when the extended text is clicked
Intent intent = new Intent(this, MyActivity.class);
PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, expandedTitle, expandedText, launchIntent);
// Notification显示时会伴随音乐
// Notification.DEFAULT_VIBRATE:振动;Notification.DEFAULT_ALL:音乐+振动
notification.defaults = Notification.DEFAULT_SOUND;
使用setLastestEventInfo可更新数据集以呈现最新的消息(例如,接收多个SMS消息时更新SMS的数目)。任何对Notification的变更都需要重新触发setLastestEventInfo。振动需要在AndroidManifest.xml里进行下类设定
<uses-permission android:name="android.permission.VIBRATE"/>
3. Notification的触发和取消
NotificationManager.notify()和NotificationManager.cancel()。
每一个Notification都有一个唯一的id,这个id是开发者来指定的。
分享到:
相关推荐
目录这里我们分步解题:第一步:判断API第二步:NotificationChannel第三步:Notification第二个参数代码对比:拓展 这几天做一个小软件在API28(Android 9.0)的模拟器上测试时,发现通知栏无效,经过一番查询,...
Notification
Notification最新用法、实现Notification的通知栏常驻、Notification的各种样式big View、解决Notification点击无效
这个例子演示Android 在状态栏添加Notification信息图标及提示,相信大家对这个功能已经不陌生了,手机中安装的APP,一般都会在后台运行,时不时会在手机顶部的状态栏中显示应用的图标,滑出状态栏会看到详细的信息...
主要利用了notification service 和receiver 实现了用户通知栏更新,失败了点击重新下载,下载好了点击自动安装,布局很丑,请根据自己项目的实际需求自行修改
使用javascript 封装实现 Notification 消息通知框
各种Notification的使用技巧
类型:NotificationDemo 功能:从网上下载apk存储到手机指定目录,并在通知栏里显示其下载进度,如果下载错误,或者不想要该apk可以删除 涉及知识: 文件流、网络下载链接协议、读写权限、Handler、Notification、...
可以设置一条通知,当然可以更新一条通知,我们通过在调用NotificationManager.notify(ID, notification)时所使用的ID来更新它。为了更新你之前发布的通知,你需要更新或者创建一个NotificationCompat.Builder对象,...
实现自定义的弹出通知视图(Notification)-定制颜色、图标等 [注意:本资源来自网络,如有侵权,请联系我删除,谢谢。]
Bluetooth Alert Notification Profile
Notification的使用示例各种效果,包含系统一般notification的示例,以及自定义铃声震动等
oracle:Heap size 3597K exceeds notification threshold 解决方法
android notification完全解析Demo
Notification顶部通知栏demo
Android实现Notification的通知栏常驻.zip