public static synchronized boolean isVoicePermission() { AudioRecord record = null; try { record = new AudioRecord(MediaRecorder.AudioSource.MIC, 22050, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(22050, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT)); record.startRecording(); int recordingState = record.getRecordingState(); if (recordingState == AudioRecord.RECORDSTATE_STOPPED) { return false; } //第一次 為true時,先釋放資源,在進行一次判定 //************ record.release(); record = new AudioRecord(MediaRecorder.AudioSource.MIC, 22050, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(22050, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT)); record.startRecording(); int recordingState1 = record.getRecordingState(); if (recordingState1 == AudioRecord.RECORDSTATE_STOPPED) { } //************** //如果兩次都是true, 就返回true 原因未知 return true; } catch (Exception e) { return false; } finally { if (record != null) { record.release(); } } }
只判定一次的話 ,一般第一次拒絕 會得到true,表示有權限,但是再次獲取 就會為false,不知道什么原理
據說是判定有沒有被占用,表示疑問