69#ifdef QT_UTILITIES_OPEN_VIA_ACTIVITY
70 if (
const auto context = QNativeInterface::QAndroidApplication::context(); context.isValid()) {
71 auto env = QJniEnvironment();
72 if (
auto openPathMethod = env.findMethod(context.objectClass(),
"openPath",
"(Ljava/lang/String;)Z")) {
73 return env->CallBooleanMethod(context.object(), openPathMethod, QJniObject::fromString(path).object()) == JNI_TRUE;
78 QUrl url(QStringLiteral(
"file://"));
83 tmp.replace(QChar(
'\\'), QChar(
'/'));
86 if (QFileInfo(path).isAbsolute()) {
87 tmp = QStringLiteral(
"/") + tmp;
89 url.setPath(tmp, QUrl::DecodedMode);
92 url.setPath(path, QUrl::DecodedMode);
94 return QDesktopServices::openUrl(url);
100 if (
const auto context = QNativeInterface::QAndroidApplication::context(); context.isValid()) {
101 auto env = QJniEnvironment();
102 if (
auto showToastMethod = env.findMethod(context.objectClass(),
"showToast",
"(Ljava/lang/String;I)Z")) {
103 return env->CallBooleanMethod(context.object(), showToastMethod, QJniObject::fromString(message).object(), duration) == JNI_TRUE;
161QMetaObject::Connection
onDarkModeChanged(std::function<
void(
bool)> &&darkModeChangedCallback, QObject *context,
bool invokeImmediately)
163#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
164 if (
const auto *
const styleHints = QGuiApplication::styleHints()) {
165 if (invokeImmediately) {
166 darkModeChangedCallback(styleHints->colorScheme() == Qt::ColorScheme::Dark);
168 return QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, context,
169 [handler = std::move(darkModeChangedCallback)](Qt::ColorScheme colorScheme) {
return handler(colorScheme == Qt::ColorScheme::Dark); });
172 Q_UNUSED(darkModeChangedCallback)
174 Q_UNUSED(invokeImmediately)
176 return QMetaObject::Connection();
QT_UTILITIES_EXPORT QMetaObject::Connection onDarkModeChanged(std::function< void(bool)> &&darkModeChangedCallback, QObject *context=nullptr, bool invokeImmediately=true)
Invokes the specified callback when the color scheme changed.