Android中通知的基本使用

xiaoxiao2021-02-28  8

核心代码:

private void method(){ NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle("测试标题")//设置通知栏标题 .setContentText("测试内容") //<span style="font-family: Arial;">/设置通知栏显示内容</span> .setTicker("菱感工程管理已退出登录") //通知首次出现在通知栏,带上升动画效果的 .setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间 .setPriority(Notification.PRIORITY_DEFAULT) //设置该通知优先级 .setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消 .setOngoing(false)//ture,设置他为一个正在进行的通知。他们通常是用来表示一个后台任务,用户积极参与(如播放音乐)或以某种方式正在等待,因此占用设备(如一个文件下载,同步操作,主动网络连接) .setDefaults(Notification.DEFAULT_VIBRATE)//向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合 .setSmallIcon(R.mipmap.ic_launcher)//设置通知小ICON .setDefaults(Notification.DEFAULT_SOUND)//获取默认铃声 .setVibrate(new long[]{0, 300, 500, 300});//设置震动 // 点击后跳转 Intent intent = new Intent(MainActivity.this,NotificationActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); mBuilder.setContentIntent(pendingIntent); mNotificationManager.notify(1, mBuilder.build()); }

源码下载 http://download.csdn.net/download/zhaihaohao1/10211585  参考文章 http://blog.csdn.net/vipzjyno1/article/details/25248021/ 

转载请注明原文地址: https://www.6miu.com/read-2000280.html

最新回复(0)