Use new permission api for http example

Change-Id: I265ec42205a193e9862eef26e73805bbf4188640
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Assam Boudjelthia 2021-06-07 11:55:46 +03:00
parent 8ee2186830
commit 19a154f57b
3 changed files with 6 additions and 33 deletions

View File

@ -36,16 +36,6 @@ target_link_libraries(http PUBLIC
Qt::Widgets Qt::Widgets
) )
if(ANDROID AND TARGET Qt::AndroidExtras)
target_compile_definitions(http PUBLIC
REQUEST_PERMISSIONS_ON_ANDROID
)
target_link_libraries(http PUBLIC
Qt::AndroidExtras
)
endif()
install(TARGETS http install(TARGETS http
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"

View File

@ -1,8 +1,4 @@
QT += network widgets QT += network widgets
android: qtHaveModule(androidextras) {
QT += androidextras
DEFINES += REQUEST_PERMISSIONS_ON_ANDROID
}
HEADERS += httpwindow.h HEADERS += httpwindow.h
SOURCES += httpwindow.cpp \ SOURCES += httpwindow.cpp \

View File

@ -53,30 +53,17 @@
#include <QScreen> #include <QScreen>
#include "httpwindow.h" #include "httpwindow.h"
#ifdef REQUEST_PERMISSIONS_ON_ANDROID
#include <QtAndroid>
bool requestStoragePermission() {
using namespace QtAndroid;
QString permission = QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE");
const QHash<QString, PermissionResult> results = requestPermissionsSync(QStringList({permission}));
if (!results.contains(permission) || results[permission] == PermissionResult::Denied) {
qWarning() << "Couldn't get permission: " << permission;
return false;
}
return true;
}
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
#ifdef REQUEST_PERMISSIONS_ON_ANDROID
if (!requestStoragePermission()) auto permission = QPermission::WriteStorage;
if (QCoreApplication::requestPermission(permission).result() != QPermission::Authorized) {
qWarning() << "Couldn't get 'WriteStorage' permission!";
return -1; return -1;
#endif }
HttpWindow httpWin; HttpWindow httpWin;
const QRect availableSize = httpWin.screen()->availableGeometry(); const QRect availableSize = httpWin.screen()->availableGeometry();
httpWin.resize(availableSize.width() / 5, availableSize.height() / 5); httpWin.resize(availableSize.width() / 5, availableSize.height() / 5);