Notification 詳細運用

2021-06-09 03:17:47 字數 1157 閱讀 7267

setcontentview(r.layout.activity_main);

//notificationmanager獲取notification_service

final notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service);

findviewbyid(r.id.button1)

.setonclicklistener(

new onclicklistener() ;

//系統鈴聲

string ringname = ringtonemanager

.getactualdefaultringtoneuri(

mainactivity.this,

ringtonemanager.type_ringtone)

.tostring();

notification.sound = uri

.parse(ringname);

//閃光燈

notification.ledonms=300;

notification.ledoffms=1000;

//切換到另乙個activity

pendingintent pendingintent = pendingintent

.getactivity(

mainactivity.this,

0,new intent(

mainactivity.this,

mainactivity.class),

0);//資訊

notification

.setlatesteventinfo(

mainactivity.this,

"notification",

"this is test notification",

pendingintent);

notificationmanager

.notify(0,

notification);

}});

}@override

public boolean oncreateoptionsmenu(

menu menu)

}

Notification高度問題

最近用到了自定義的notification布局 高度突然顯示不全,是因為在預設情況下低版本只有 builder.setcontent remoteviews 預設高度64 超出則顯示不全 而在api16 以上提供了bigcontenteview builder.setcustombigcontent...

高階Notification技巧

在接下來的章節,你將學習如何增強 notification 功能 通過硬體來提供額外的警示,如讓裝置響鈴 閃光和振動。上述描述的每個增強功能,你都將看到乙個 片段,你可以將它們新增到 earthquake 例子中,在每次檢測到 時,都會給使用者提供反饋。在這裡描述的 notification 技巧中...

新增常駐Notification

private static final int notification id 250 用來標示notification,通過notificatinomanager來發布同樣標示的notification將更新舊的通知,同時取消notification也需要這個標示 android很多地方都用到標...