Android得到一个闹钟在第三方
收集報(bào)警信息
鬧鈴時(shí)間,鬧鈴備注信息
?
鬧鈴引起系統(tǒng)變化的點(diǎn):
1. Send Notification (正點(diǎn)鬧鐘能夠設(shè)置不發(fā)送)
2. Play audio
?
鬧鈴信息結(jié)構(gòu)體
ClockInfo{
String apkName;
String startTime;
String backup;
}
?
SendNotification
SystemUI
BaseStatusBar.java
在BaseStatusBar獲取鬧鐘發(fā)送的notification。由于某些第三方鬧鐘(比方:正點(diǎn)鬧鐘)發(fā)送的notification并不表示鬧鈴事件,這時(shí)須要推斷系統(tǒng)是否正在播放鬧鈴。
怎樣推斷系統(tǒng)是否正在播放鬧鈴:
Android AudioManager.java里有一個(gè)方法 /** ??? * *Checks whether any music is active. ??? * @return true if any music tracks are active. */ public boolean isMusicActive() { ?????? return AudioSystem.isStreamActive(STREAM_MUSIC, 0); } 用來(lái)Checks whether any music is active. 注意AudioSystem.isStreamActive(STREAM_MUSIC,0),這里方法的STREAM_MUSIC參數(shù),用來(lái)表示當(dāng)前stream type.而對(duì)于鬧鈴應(yīng)用一般的stream type 是STREAM_ALARM.為了 Checks whether any alarm is active 或者check other stream type is active,在AudioManager添加方法: ?/**
?* Checks whether the specified stream type is active.
?*
?* return true if this stream is active.
?*/
public boolean?isStreamActive(intstream){
??????? return AudioSystem.isStreamActive(stream,0);
?}?
在BaseStatusBar里推斷是否在播放鬧鈴:
AudioManager audioManager =(AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
??????? if (null == audioManager)
??????? {
??????????? Log.e(TAG, "Failed to get AudioManager");
??????????? return;
???????}
?
if (!audioManager.isStreamActive(AudioManager.STREAM_ALARM)
??????????????? && !Common.DIANXIN_PACKAGENAME.equals(currentPackageName))
??????? {
??????????? Log.i(TAG,
???????????????????"Stream not active and current package name isn'tdianxin");
??????????? return;
???????}
使用AudioManager.STREAM_ALARM當(dāng)做參數(shù)來(lái)推斷是否有Alarm播放。為什么后面還須要加上Common.DIANXIN_PACKAGENAME.equals(currentPackageName)?
由于點(diǎn)心鬧鐘播放鈴聲時(shí),STREAM_TYPE不是AudioManager.STREAM_ALARM,檢測(cè)發(fā)現(xiàn)它的Stream type是動(dòng)態(tài)變化的。但點(diǎn)心鬧鐘僅僅有鬧鈴的時(shí)候才發(fā)送notification.
所以依據(jù)
if (!audioManager.isStreamActive(AudioManager.STREAM_ALARM)
??????????????? && !Common.DIANXIN_PACKAGENAME.equals(currentPackageName))
??????? {
??????????? Log.i(TAG,
???????????????????"Stream not active and current package name isn'tdianxin");
??????????? return;
???????}
我們就能推斷出當(dāng)前是否是在鬧鈴。
?
版權(quán)聲明:本文博主原創(chuàng)文章。博客,未經(jīng)同意不得轉(zhuǎn)載。
總結(jié)
以上是生活随笔為你收集整理的Android得到一个闹钟在第三方的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 总和最大区间问题
- 下一篇: Android中弹出对话框,AlertD