一、拿到NotificationManager manager= (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
二、创建Notification notification = new Notification(R.drawable.icon,"This is ticket text",System.currentTimeMillis());
第一个参数用于指定通知图标。第二个参数用于指定通知的ticker内容,当通知刚被创建时,会在状态栏一闪而过。第三个参数指定通知创建时间,当下拉系统状态栏时,这个时间会显示在相应的通知上。
三、指定通知的实际标题和内容。notification.setLatestEventInfo(context,"This is content title","This is content text",null);
四、发出通知manager.notify(1,notification);//第一个参数表示通知id不能重复
五、点击通知跳转到NotificationActivity,使用延时执行的intent,即PendingIntent
Intent intent = new Intent(this,Notification.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context,"This is content title","This is content text",pi);//第四个参数
manager.notify(1,notification);
六、打开NotificationActivity时,要关闭通知栏。
public class NotificationActivity extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.notification_layout);
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
manager.cancel(1);//nofify中第一个参数使用的id
}
}
七、为通知加上声音和振动,LED闪烁
可以直接使用通知的默认效果notification.defaults = Notificaion.DEFAULT_ALL;
Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/Basic_tone.ogg"));
notification.sound = soundUri;
long[] vibrates = {0,1000,1000,1000};//静止时长,振动时长,静止时长……
notification.vibrate = vibrate;
notification.ledARGB = Color.GREEN;
notification.ledOnMS = 1000;//亮起时长
notification.ledOffMS = 1000;//暗去时长
notification.flags = Notificaion.FLAG_SHOW_LIGHTS;
相关推荐
通知栏接受消息跳转到相应的界面的处理
Android通知栏拦获微信消息
这个是通知栏框架(Notificaiton)的全面学习,里面把大概所有的情况都列了出来,通过一个DEMO让你了解它的大致所有使用过程。 可以通过以下博文进行配套了解(有效果图): ...
delphi android通知消息栏内容显示的实现,包括多行单行消息。
通知栏内更新,下载完成自动安装并清除消息通知,已修改测试,可直接用于项目
使用NotificationListenerService写了一个监听Android通知栏的程序
android对通知栏的操作 利用service而不是notifymanager 在程序崩溃或强制退出的时候通知栏图标能够主动消失
很全的android通知栏学习,包含apk下载,通知栏消失,通知栏跳转
Android通知栏实现
这几天做一个小软件在API28(Android 9.0)的模拟器上测试时,发现通知栏无效,经过一番查询,了解到:API26(Android 8.0)以后,引入了**通知渠道(Notification Channels)**这么一个东西来帮助用户管理通知。...
Android 通知栏。
这里面详细介绍了android通知栏的实现方法,需要将此功能集成在程序中的程序员可以看一下
模拟通知栏提示下载进度,这是一个学习源码。如果想做一个升级下载功能,然后在通知栏里面显示进度,这将是一个非常不错的选择。
Android通知栏Notification效果代码简单演示,属于本人复习所用。
Android实现Notification的通知栏常驻.zip
Android通知栏消息、点亮屏幕、震动、声音、显示样式的小例子。
一个简单的android project。点击一个按钮。通知栏出现一个正在下载的通知。。无其他实质功效。
[Deprecated]【废弃,已不适用于新版本的android系统】Android通知栏消息工具类。A lite of “pugnotification” for creating notifications in android platform.. 软件开发设计:PHP、QT、应用软件开发、系统软件...
这个是android notification框架,如有需要请下载。发发发
android 在service里面下载,在通知栏和activity里面同时显示下载进度