編輯:關於Android編程
正文
[DESCRIPTION]
插入耳機端口,打開音樂。側鍵音量開到最大,出現提示框“將音量調高到安全級別以上?會損壞聽力”這樣的提示。而同樣的路徑打開收音機,點擊側音量鍵把音量調到最大,沒有相應的提示。
[SOLUTION]
修改
1, private static final int MSG_CHECK_FM_ACTIVE = 29;
2,
private void onCheckFmActive() {
synchronized (mSafeMediaVolumeState) {
if (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE) {
int device = getDeviceForStream(AudioSystem.STREAM_FM);
if ((device & mSafeMediaVolumeDevices) != 0) {
sendMsg(mAudioHandler, MSG_CHECK_FM_ACTIVE, SENDMSG_REPLACE, 0, 0, null,
FM_ACTIVE_POLL_PERIOD_MS);
int index = mStreamStates[AudioSystem.STREAM_FM]
.getIndex(device, false /* lastAudible */);
if (AudioSystem.isStreamActive(AudioSystem.STREAM_FM, 0)
&& (index > mSafeMediaVolumeIndex)) {
// Approximate cumulative active music time
mFmeMs += FM_ACTIVE_POLL_PERIOD_MS;
if (mFmeMs > UNSAFE_VOLUME_FM_ACTIVE_MS_MAX) {
setSafeMediaVolumeEnabled(true);
mFmeMs = 0;
mVolumePanel.postDisplaySafeVolumeWarning();
}
}
}
}
}
}
3,
在 case MSG_CHECK_MUSIC_ACTIVE:
onCheckMusicActive();
break;
後面增加
/// M: safe media for FM @{
case MSG_CHECK_FM_ACTIVE:
onCheckFmActive();
break;
/// safe media for FM @}
4, 在 private void onSetWiredDeviceConnectionState(int device, int state, String name)
sendMsg(mAudioHandler,
MSG_CHECK_MUSIC_ACTIVE,
SENDMSG_REPLACE,
0,
0,
null,
MUSIC_ACTIVE_POLL_PERIOD_MS);
後面增加
/// safe media for FM @{
sendMsg(mAudioHandler, MSG_CHECK_FM_ACTIVE, SENDMSG_REPLACE, 0, 0, null,
FM_ACTIVE_POLL_PERIOD_MS);
/// safe media for FM @}
5,
在 private static final int SAFE_VOLUME_CONFIGURE_TIMEOUT_MS = 30000; // 30s after boot completed
後面增加如下
private int mFmeMs;
private static final int UNSAFE_VOLUME_FM_ACTIVE_MS_MAX = (20 * 3600 * 1000); // 20
// hours
private static final int FM_ACTIVE_POLL_PERIOD_MS = 60000; // 1 minute
6,以下幾個函數改為如下
private void setSafeMediaVolumeEnabled(boolean on) {
synchronized (mSafeMediaVolumeState) {
if ((mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_NOT_CONFIGURED)
&& (mSafeMediaVolumeState != SAFE_MEDIA_VOLUME_DISABLED)) {
if (on && (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_INACTIVE)) {
mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_ACTIVE;
enforceSafeMediaVolume();
} else if (!on && (mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE)) {
mSafeMediaVolumeState = SAFE_MEDIA_VOLUME_INACTIVE;
mMusicActiveMs = 0;
sendMsg(mAudioHandler, MSG_CHECK_MUSIC_ACTIVE, SENDMSG_REPLACE, 0, 0, null,
MUSIC_ACTIVE_POLL_PERIOD_MS);
mFmeMs = 0;
sendMsg(mAudioHandler, MSG_CHECK_FM_ACTIVE, SENDMSG_REPLACE, 0, 0, null,
FM_ACTIVE_POLL_PERIOD_MS);
}
}
}
}
private void enforceSafeMediaVolume() {
enforceSafeMediaVolume(AudioSystem.STREAM_MUSIC);
enforceSafeMediaVolume(AudioSystem.STREAM_FM);
}
private void enforceSafeMediaVolume(int streamType) {
VolumeStreamState streamState = mStreamStates[streamType];
boolean lastAudible = (streamState.muteCount() != 0);
int devices = mSafeMediaVolumeDevices;
int i = 0;
while (devices != 0) {
int device = 1 << i++;
if ((device & devices) == 0) {
continue;
}
int index = streamState.getIndex(device, lastAudible);
if (index > mSafeMediaVolumeIndex) {
if (lastAudible) {
streamState.setLastAudibleIndex(mSafeMediaVolumeIndex, device);
sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, SENDMSG_QUEUE, PERSIST_LAST_AUDIBLE,
device, streamState, PERSIST_DELAY);
} else {
streamState.setIndex(mSafeMediaVolumeIndex, device, true);
sendMsg(mAudioHandler, MSG_SET_DEVICE_VOLUME, SENDMSG_QUEUE, device, 0,
streamState, 0);
}
}
devices &= ~device;
}
}
private boolean checkSafeMediaVolume(int streamType, int index, int device) {
synchronized (mSafeMediaVolumeState) {
if ((mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE)
&& (mStreamVolumeAlias[streamType] == AudioSystem.STREAM_MUSIC || mStreamVolumeAlias[streamType] == AudioSystem.STREAM_FM)
&& ((device & mSafeMediaVolumeDevices) != 0) && (index > mSafeMediaVolumeIndex)) {
mVolumePanel.postDisplaySafeVolumeWarning();
return false;
}
return true;
}
}
/// safe media for FM @}
(alps/frameworks/base/media/java/android/media/AudioService.java)
然後
mk xxx(project_name) mm frameworks/base
adb remount
adb push framework.jar system/framework
adb reboot
即可驗證功能。
Android 仿照微信發說說,既能實現拍照,選圖庫,多圖案上傳,使用Retrofit技術。使用方法:詳見http://www.jb51.net/article/1030
概述:MediaRecorder的狀態圖:代碼:開始錄制音頻:mRecorder = new MediaRecorder(); //Sets
眾所周知,根據mvc設計模式,數據是要通過model來傳遞的,從一個activity(以下簡稱A)到另外一個activity(以下簡稱B)如果要傳值的話我們可
monkeyrunner腳本使用Python語法編寫,但它實際上是通過Jython來解釋執行。 Jython是Python的Java實現,它將Python代碼解釋成Jav