作者ivanf10710 (Ivan)
看板AndroidDev
标题[问题] Notification相关问题
时间Mon Jun 25 03:18:13 2012
code:
protected void showNotification() {
NotificationManager barManager =
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification barMsg = new Notification(R.drawable.icon, "text",
System.currentTimeMillis());
PendingIntent content = PendingIntent.getActivity(this, 0,
new Intent(this, Other.class), PendingIntent.FLAG_UPDATE_CURRENT);
barMsg.setLatestEventInfo(Main.this, "text", "text", content);
barManager.notify(0, barMsg);}
新手上路,多多包涵
以上这段大致上就是用NotificationManager管理讯息提醒框架
然後宣告一个Notification类型的物件放显示的讯息内容
可是我写好以後Eclipse出现了黄字警告
他说:Notification的constructor以及setLatestEventInfo已经deprecated了
叫我用Notification.Builder来取代
因此我试着写:
Notification.Builder(Main.this)
.setSmallIcon(R.drawable.icon)
.setContentTitle(getString(R.string.title))
.setContentText(getString(R.string.text))
.setContentInfo(getString(R.string.info))
.setWhen(System.currentTimeMillis())
.setContentIntent(content);
用了他许多的method取代掉Notificaionu的建构子以及setLatestEventInfo方法
但是之後我就不会写了= =
我该怎麽把Notification.Builder的内容丢到barMsg?
因为必须要呼叫NotificaionManager的notify(int id, Notificaion notification)
所以我一定要使用Notification才行,但是我又不知道该怎麽把Notificaion.Builder
的内容丢到barMsg,请问我该怎麽写呢@@
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.45.245.210
1F:→ passli:barMsg = builder.getNotification(); 06/25 10:40
2F:→ ivanf10710:谢谢,我刚刚也在网路上找到了XD 06/25 10:41
4F:→ ivanf10710:der,否则会警告deprecated 06/25 10:44