日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android得到一个闹钟在第三方

發(fā)布時(shí)間:2023/12/10 Android 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android得到一个闹钟在第三方 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


收集報(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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。