Android得到一个闹钟在第三方


收集报警信息


闹铃时间,闹铃备注信息

 

闹铃引起系统变化的点:

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;

       }

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

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值