我正在尝试为来电和拨出电话制作自定义布局,并且在通话正在进行时,将显示特定图像,即使用户覆盖接近传感器也必须保持可见。我试过wakelock但没有成功,现在我正在使用接近传感器,它只是隐藏按钮并保留图像显示。这适用于某些手机和所有仿真器,但很少有三星和索尼手机只需在靠近传感器时关闭屏幕。这是我的接近传感器代码:
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public void onSensorChanged(SensorEvent event) {
float distance = event.values[0];
if(distance < 4){
buttonsLayout.setVisibility(View.INVISIBLE);
}
else {
buttonsLayout.setVisibility(View.VISIBLE);
}
}
感谢任何帮助。
编辑:
我正在打电话:
android.telephony.PhoneStateListener
android.telephony.TelephonyManager
com.android.internal.telephony.ITelephony (using reflection)
这是我接受电话的方式:
private void acceptCall() {
timerLayout.setVisibility(View.VISIBLE);
answerButton.setVisibility(View.GONE);
startTime = SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
try {
Runtime.getRuntime().exec("input keyevent " +
Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK));
} catch (IOException e) {
String enforcedPerm = "android.permission.CALL_PRIVILEGED";
Intent btnDown = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
Intent btnUp = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
sendOrderedBroadcast(btnDown, enforcedPerm);
sendOrderedBroadcast(btnUp, enforcedPerm);
}
}