I currently need to capture the moment when an outgoing call begins ringing. According to Abeer Ahmad in "How to identify the ringing state of outgoing call in android", a solution would be to detect the frequency change of the emitted sound (from 0 to the value corresponding to the ring) using the Visualizer class. However, no frequency value other than 0 (silence) is detected while I make a call. This does not correspond to what happens when the mobile emits another sound, such as the reproduction of an audio track, where the frequency values are detected. Could someone help me, or give me an alternative solution?
Here is my code:
mVisualizer = new Visualizer(0);
mVisualizer.setCaptureSize(Visualizer.getCaptureSizeRange()[1]);
Visualizer.OnDataCaptureListener listener = new Visualizer.OnDataCaptureListener(){
@Override
public void onWaveFormDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) { }
@Override
public void onFftDataCapture(Visualizer visualizer, byte[] bytes, int samplingRate) {
for (int i=0;i<bytes.length;i++) {
if (bytes[i] != 0) {
Log.i("INFO","FREQUENCY:"+bytes[i]);
break;
}
}
}
};
mVisualizer.setDataCaptureListener(listener, Visualizer.getMaxCaptureRate() / 2, true, true);
I'm using Android Jellybean (API 17).