Notification的特殊應用

2021-05-23 09:05:44 字數 2404 閱讀 4410

notification

這個我想幾乎大家都應該非常熟悉了

, 平時我們多數用的時候只是簡單的使用了它的通知效果

, 其實它還有很多特殊功能

. 我不知道之前是否已經有人做過此相關文件了

, 以下只是我個人最近才學到的東西

, 很多例子也都是要在真機上面才會有效果的

. 所以有興趣的人就用真機跑一下吧

… 不同手機可能會有不同的效果哦

….目前我只在

g3嘗試過

notification

有很多公開的變數, 如

,android

notification

,通過給

sound

屬性設定乙個位置

uri,如下面的**片段所示:

notification.sound = ringuri;

例如:uri ringuri = uri.fromfile(new file(「/system/media/audio/ringtones/ringer.***」));

notification.sound = ringuri;

你可以使用手機的震動函式來針對

notification

來讓手機執行特定樣式的震動。

android

允許你控制震動的樣式;你可以使用震動來傳達資訊以獲取使用者的注意。

為了設定震動樣式,給

notification

的vibrate

屬性設定乙個時間陣列。構建乙個陣列,每個間隔的數字相應地代表震動或暫停的時間長度(公釐為單位)。

在你的程式中使用震動之前,你需要給程式授予許可權。使用下面的**片段來為應用程式新增

uses-permission

節點:

接下來的例子顯示了如何修改

notification

的震動,以重複的方式

1秒震動、

1秒停止,共5秒。

long vibrate = new long ;

notification.vibrate = vibrate;

你可以利用這個細微的控制來向使用者傳遞資訊。

目前的android

模擬器不能直觀的或者可聽見的感受到裝置的震動。為了證實

notification

工作正常,你可以監視「

vibration on」/

「vibration off

」的log

輸出。notification

也包含屬性來設定手機

led的顏色和閃爍頻率

ledargb

屬性用於設定

led的顏色,而

ledoffms

和ledonms

屬性用來設定

led閃爍的頻率和樣式。你可以設定

ledonms

屬性為1

,ledoffms

屬性為0

來讓led

始終亮著;或者將兩者設定為0來將

led關閉。一旦你設定了

led的設定,你也必須為notification

的flags

屬性新增

flag_show_lights

標誌位。

接下來的**片段顯示了如何將點亮紅色的

led:

notification.ledargb = color.red;

notification.ledoffms = 0;

notification.ledonms = 1;

notification.flags = notification.flags | notification.flag_show_lights;

led能設定顏色是官方的文件說的

,可是我自己用

g3測試過

, 不管設定什麼顏色都只是閃綠燈

, 所以希望有不同機型的同學也幫忙測試下

, 看看是不是官方的文件有問題

通過設定

flag_insistent

和flag_ongoing_event

標誌位可以讓

notification

成為持續或正在進行的

notification

。具體不同的通知型別我自己上解釋吧

.顧名思義

, //

設定預設

default_lights 

預設燈//default_sound  

預設聲音

//default_vibrate 

預設震動

//default_all

以上預設

//notificaion.defaults = notification.default_all;

折騰人的Notification

低於api level 11版本,也就是android 2.3.3以下的系統中,setlatesteventinfo 函式是唯一的實現方法。intent intent new intent this,mainactivity pendingintent pendingintent pendingin...

Notification 詳細運用

setcontentview r.layout.activity main notificationmanager獲取notification service final notificationmanager notificationmanager notificationmanager gets...

Notification高度問題

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