收集报警信息

闹铃时间,闹铃备注信息

闹铃引起系统变化的点:

1. Send Notification (正点闹钟能够设置不发送)

2. Play audio

闹铃信息结构体

ClockInfo{

String apkName;

String startTime;

String backup;

}

SendNotification

SystemUI

BaseStatusBar.java

在BaseStatusBar获取闹钟发送的notification。由于某些第三方闹钟(比方:正点闹钟)发送的notification并不表示闹铃事件,这时须要推断系统是否正在播放闹铃。

怎样推断系统是否正在播放闹铃:

Android AudioManager.java里有一个方法
/**
    * 
    *Checks whether any music is active.
    * @return true if any music tracks are active.
 */
public boolean isMusicActive() {
       return AudioSystem.isStreamActive(STREAM_MUSIC, 0);
}
用来Checks whether any music is active.
注意AudioSystem.isStreamActive(STREAM_MUSIC,0),这里方法的STREAM_MUSIC參数,用来表示当前stream type.而对于闹铃应用一般的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当做參数来推断是否有Alarm播放。为什么后面还须要加上Common.DIANXIN_PACKAGENAME.equals(currentPackageName)?

由于点心闹钟播放铃声时,STREAM_TYPE不是AudioManager.STREAM_ALARM,检測发现它的Stream type是动态变化的。但点心闹钟仅仅有闹铃的时候才发送notification.

所以依据

if (!audioManager.isStreamActive(AudioManager.STREAM_ALARM)

&& !Common.DIANXIN_PACKAGENAME.equals(currentPackageName))

{

Log.i(TAG,

"Stream not active and current package name isn'tdianxin");

return;

}

我们就能推断出当前是否是在闹铃。

版权声明:本文博主原创文章。博客,未经同意不得转载。

05-06 02:47
查看更多