我们遇到了同样的问题。我们真正检测到的是,当使用 WakeLock 关闭屏幕时,输入套接字停止接收数据,因此我们向 AudioTrack 发送了零。
为了改善这一点,我们停止使用 PROXIMITY_SCREEN_OFF_WAKE_LOCK,现在使用 SensorManager(我们查看了 Linphone 代码):
public class InCallActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mProximity;
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
public void onSensorChanged(SensorEvent event) {
final Window window = getWindow();
WindowManager.LayoutParams lAttrs = getWindow().getAttributes();
View view = ((ViewGroup) window.getDecorView().findViewById(android.R.id.content)).getChildAt(0);
if (event.values[0] > 4) {
// turn on screen
Log.v("LlamadaActivity", "Encendemos pantalla");
lAttrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
view.setVisibility(View.VISIBLE);
}
else {
// turn off screen
Log.v("LlamadaActivity", "Apagamos pantalla");
lAttrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
view.setVisibility(View.INVISIBLE);
}
window.setAttributes(lAttrs);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mSensorManager.registerListener(this, mProximity, SensorManager.SENSOR_DELAY_NORMAL);
// Para que la pantalla no se apague, y que la encienda aunque este apagada y bloqueada
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//
}
@Override
protected void onDestroy() {
super.onDestroy();
mSensorManager.unregisterListener(this);
}
}