Tell me how you can determine the volume of the signal coming to the microphone of the phone. (simplistic, interested in the maximum value at a particular moment, in relation to some kind of reference). Alternatively, the ability to determine the maximum volume value in the recorded file is also of interest. Found the following code, but the return value is always 0

int maxa = 0; int minSize = AudioRecord.getMinBufferSize(16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); AudioRecord ar = new AudioRecord(MediaRecorder.AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, minSize); short[] buffer = new short[minSize]; ar.read(buffer, 0, minSize); for (short s : buffer) { if (Math.abs(s) > maxa) maxa = Math.abs(s); } ar.stop(); return maxa; 

In the manifest, specified <uses-permission android:name="android.permission.RECORD_AUDIO" />

0