[問題] Notification相關問題

看板AndroidDev作者 (Ivan)時間12年前 (2012/06/25 03:18), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
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

06/25 10:40, , 1F
barMsg = builder.getNotification();
06/25 10:40, 1F

06/25 10:41, , 2F
謝謝,我剛剛也在網路上找到了XD
06/25 10:41, 2F

06/25 10:44, , 3F
http://ppt.cc/3BKd→3.0版以上須用Notification.Build
06/25 10:44, 3F

06/25 10:44, , 4F
der,否則會警告deprecated
06/25 10:44, 4F
文章代碼(AID): #1FvsVtkx (AndroidDev)