建立乙個Notification (通知)

2021-07-15 15:10:15 字數 2015 閱讀 2227

這個例子是基於notification.builder類來實現的,最低限度的,乙個builder物件應該包括以下:

notificationcompat.builder mbuilder =

new notificationcompat.builder(this)

.setsmallicon(r.drawable

.notification_icon)

.setcontenttitle("my notification")

.setcontenttext("hello world!");

這個行為,由包含乙個intent的 pendingintent定義。

如何構造你的pendingintent,由你想要的開啟的activity的型別有關,有時候你只是開啟其中的乙個片段,那麼你必須建立乙個新的back stack,但是有時候你是開啟乙個全新的activity,那麼就不需要建立乙個backstack了,如下**:

intent resultintent = new intent(this, resultactivity.class);

...pendingintent resultpendingintent =

pendingintent.getactivity(

this,

0,resultintent,

pendingintent.flag_update_current

);

pendingintent resultpendingintent;

...mbuilder.setcontentintent(resultpendingintent);

notificationcompat.builder mbuilder;

...// sets an id for the notification

int mnotificationid = 001;

// gets an instance of the notificationmanager service

notificationmanager mnotifymgr =

(notificationmanager) getsystemservice(notification_service);

// builds the notification and issues it.

mnotifymgr.notify(mnotificationid, mbuilder.build());

建立乙個notification的最簡單方式

notificationcompat.builder mbuilder = (notificationcompat.builder) new notificationcompat.builder(this)

.setsmallicon(r.mipmap

.ic_launcher)

.setcontenttitle("hello notification")

.setcontenttext("how are you?");

intent resultintent = new intent(this,mainactivity.class);

pendingintent resultpendingintent = pendingintent.getactivity(this,0,resultintent,pendingintent.flag_update_current);

mbuilder.setcontentintent(resultpendingintent);

int id = 001

; notificationmanager manager = (notificationmanager) getsystemservice(notification_service);

manager.notify(id,mbuilder.build());

建立乙個類

c 是一門物件導向的程式語言,而物件導向的基礎就是類 使用c 建立乙個student類 class student 學生類 輸出學生的資訊 void outputstudent void void student input char name,int age,int no void student...

建立乙個image

ceph 版本 0.94 7rbd命令操作的資源有volume 預設 snap lock三類資源 using rbd to create empty image rbd create size 1024000 test1 ceph src rbd.cc main code section 定義一些後...

建立乙個raymarching

shadertoy 檢視 先解釋一波raymarching,raymatching是一種計算機圖形渲染方式,但它的潛力仍未被完全發掘。raymatching一般用於渲染體積紋理 高度圖以及解析曲面。如今,大多數遊戲用opengl或direct3d directx 來使用顯示卡的硬體加速器繪製多邊形,...