原创内容,转载请注明原文网址:http://homeqin.cn/a/wenzhangboke/jishutiandi/2019/0112/328.html
常州手机App开发培训-Android通知写法失效
notification.setLatestEventInfo不能调用了,现在用什么来替代这个呢?
//创建一个Notification对象并设置该通知的属性
Notification notification=
new
Notification.Builder(
this
)
//设置打开该通知,该通知自动消失
.setAutoCancel(
true
)
//设置显示在状态栏的提示信息
.setTicker(
"this is a ticker"
)
//设置通知的图标
.setSmallIcon(R.drawable.ic_launcher)
//设置通知内容的标题
.setContentTitle(
"Content Title"
)
//设置通知内容的内容
.setContentText(
"Content Text"
)
//设置通知震动时间,先静止0秒再震动一秒再停止一秒,再震动一秒
.setVibrate(
new
long
[]{
0
,
1000
,
1000
,
1000
})
//设置使用系统默认的声音,默认的LED灯
.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS)
//设置通知的时间
.setWhen(System.currentTimeMillis())
//设置通知将要启动的程序的Intent
.setContentIntent(pi)
.build();
//使用NotificationManager的notify()方法显示通知
//第一个参数为每个通知指定一个不同的ID,第二个参数传入Notification的对象
manager.notify(
1
, notification);
上篇:上一篇:常州网站开发设计-阿里云虚拟机部署https(SSL)
下篇:下一篇:常州手机App开发-AndroidStudio打开DDMS