我有一個聲音錄製器應用程序代碼,基於麥克風狀態。我想顯示狀態,如果麥克風已被某些其他應用程序使用,要顯示狀態,如麥克風已在使用其他記錄......就像那樣,所以我使用下面的代碼來獲取麥克風狀態在記錄器中。 getRecordingState(),但它總是返回1,即使我在呼叫或空閒。幫我拿一些代碼來獲得麥克風狀態。提前致謝。Android - 如何檢查一些其他應用程序正在使用麥克風
int[] mSampleRates = new int[]{8000, 11025, 22050, 44100};
for (int rate : mSampleRates) {
for (short audioFormat : new short[]{AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT}) {
for (short channelConfig : new short[]{AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO}) {
try {
Log.d(TAG, "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: "
+ channelConfig);
int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
// check if we can instantiate and have a success
AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, rate, channelConfig, audioFormat, bufferSize);
if (recorder.getState() == AudioRecord.STATE_INITIALIZED) {
Log.i("", "Recorder intialised " + recorder.getRecordingState() + " " + recorder.getState() + " ");
return recorder;
}
}
} catch (Exception e) {
Log.e(TAG, rate + "Exception, keep trying.", e);
}
}
}
}
return null;
看看這個http://stackoverflow.com/questions/12018927/check-if-android-mic-is-being-used-by-another-app – Sunny
感謝陽光,我沒有約想法HAL層,你可以請幫我從應用程序級別獲得狀態 – user2750213