0

我正在尝试为来电和去电进行自定义布局,并且在通话进行时,将显示特定图像,即使用户覆盖接近传感器,该图像也必须保持可见。我尝试使用唤醒锁但没有成功,现在我正在使用接近传感器,它只会隐藏按钮并留下要显示的图像。这适用于某些手机和所有模拟器,但很少有三星和索尼手机在靠近传感器时会简单地关闭屏幕。这是我的接近传感器代码:

@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);
    }
}
4

0 回答 0