首页 技术 正文
技术 2022年11月16日
0 收藏 656 点赞 2,974 浏览 1685 个字

收集报警信息

闹铃时间,闹铃备注信息

闹铃引起系统变化的点:

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;

}

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

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,024
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,514
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,362
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,776
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,854