gpt4 book ai didi

java - 在Qt中调用java函数

转载 作者:行者123 更新时间:2023-11-28 06:16:05 26 4
gpt4 key购买 nike

我们有一个让人打电话的应用程序。我想在用户接到电话时打开屏幕,并在用户关闭它时关闭它。我试过两次。第一次,我默认添加标志。它正在工作。但在第二种情况下,我不再添加了。

在 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
}

关于java - 在Qt中调用java函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30283311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com