我们有一个可以让人打电话的应用程序。我想在用户接到电话时打开屏幕,而在用户关闭电话时关闭屏幕。我已经试过两次了。第一次,我默认添加了flag。它正在工作。但在第二种情况下,我不再添加。
在java文件中,我定义了turnFlags来打开/关闭标志。
CustomMainActivity.java:
public void turnFlags(boolean onOff)
{
if(onOff)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
在C ++文件中,我决定在不同情况下使用turnFlags。我想在callInvited时将其打开,而在callClosed时将其关闭。
void VoipTask::callInvite()
{
#ifdef Q_OS_ANDROID
QtAndroid::androidActivity().callMethod<void>("turnFlags", "(Z)V", true);
#endif
CGlobalZone::m_callType = IncomingCall;
#ifdef Q_OS_ANDROID
m_answerDate = m_callDate = QDateTime::currentDateTime();
m_callState = MissedCall;
m_transactionId = QtAndroid::androidActivity().callMethod<jint>("getTransactionId");
m_callId = QtAndroid::androidActivity().callMethod<jint>("getCallId");
m_dialogId = QtAndroid::androidActivity().callMethod<jint>("getDialogId");
#else
CGlobalZone::m_dialNumber = m_callNumber;
#endif
QApplication::postEvent(CGlobalZone::m_callsManager, new QEvent(QEvent::Type(CGlobalZone::HANDLE_CALL_EVENT)));
startAudioDevices();
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
if (CGlobalZone::m_ringtone.isEmpty())
ring();
else
playRingtone();
#endif
}
void VoipTask::callClosed()
{
#ifdef Q_OS_ANDROID
QtAndroid::androidActivity().callMethod<void>("turnFlags", "(Z)V", false);
#endif
stopConversation();
stopAudioDevices();
stopVoip();
}
最佳答案
您已定义#ifdef Q_OS_ANDROID
两次。更改为:
void VoipTask::callInvite()
{
CGlobalZone::m_callType = IncomingCall;
#ifdef Q_OS_ANDROID
m_answerDate = m_callDate = QDateTime::currentDateTime();
m_callState = MissedCall;
QtAndroid::androidActivity().callMethod<void>("turnFlags", "(Z)V", true);
m_transactionId = QtAndroid::androidActivity().callMethod<jint>("getTransactionId");
m_callId = QtAndroid::androidActivity().callMethod<jint>("getCallId");
m_dialogId = QtAndroid::androidActivity().callMethod<jint>("getDialogId");
#else
CGlobalZone::m_dialNumber = m_callNumber;
#endif
QApplication::postEvent(CGlobalZone::m_callsManager, new QEvent(QEvent::Type(CGlobalZone::HANDLE_CALL_EVENT)));
startAudioDevices();
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
if (CGlobalZone::m_ringtone.isEmpty())
ring();
else
playRingtone();
#endif
}