温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Notification通知

发布时间:2020-07-07 23:51:31 来源:网络 阅读:296 作者:清甘茶 栏目:开发技术

  NotificationManager是负责通知用户事件的发生,有三个方法:

1:  cancel(id)取消广播,假如这是一个暂时的广播,则将其隐藏,如果是个持久的,则将其从中去除掉。

2:cancelAll():取消以前显示的所有通知

3:notify(int id,Notification notification)把通知持久的发送到状态条中。

    下面直接把代码贴上,代码中有详细解释

    

private void addNotification() {

//获取通知服务

NotificationManager manager = (NotificationManager) this

.getSystemService(Context.NOTIFICATION_SERVICE) ;

Notification notifi = new Notification() ;

notifi.icon = R.drawable.ic_launcher ;//通知时候显示的图片

notifi.tickerText = "这是通知" ;

notifi.defaults = Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE ;//系统默认通知的声音

//andioStreamType的值必须AudioManager的值,代表着响铃模式

notifi.audioStreamType = android.media.AudioManager.ADJUST_LOWER ;

long[] vibreate= new long[]{1000,1000};  //震动的参数,震动一秒暂停一秒

notifi.vibrate = vibreate ;

Intent in = new Intent(MainActivity.this,SecondActivity.class) ;//点击之后所跳转到的activity

PendingIntent pend = PendingIntent.getActivity(this, 0, in, PendingIntent.FLAG_ONE_SHOT) ;

notifi.setLatestEventInfo(this, "这是标题吗", "这是内容", pend);

manager.notify(0, notifi);//执行通知,这个0是用来区分这个广播的唯一标志,下面一句话中的0就是例证

//manager.cancel(0);//取消通知

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI