Skip to content

Commit

Permalink
Use new permission api for http example
Browse files Browse the repository at this point in the history
Change-Id: I265ec42205a193e9862eef26e73805bbf4188640
Reviewed-by: Tor Arne Vestbø <[email protected]>
  • Loading branch information
Issam-b committed Jun 7, 2021
1 parent 8ee2186 commit 19a154f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
10 changes: 0 additions & 10 deletions examples/network/http/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ target_link_libraries(http PUBLIC
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
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
Expand Down
4 changes: 0 additions & 4 deletions examples/network/http/http.pro
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
QT += network widgets
android: qtHaveModule(androidextras) {
QT += androidextras
DEFINES += REQUEST_PERMISSIONS_ON_ANDROID
}

HEADERS += httpwindow.h
SOURCES += httpwindow.cpp \
Expand Down
25 changes: 6 additions & 19 deletions examples/network/http/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,17 @@
#include <QScreen>

#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[])
{
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;
#endif
}

HttpWindow httpWin;
const QRect availableSize = httpWin.screen()->availableGeometry();
httpWin.resize(availableSize.width() / 5, availableSize.height() / 5);
Expand Down

0 comments on commit 19a154f

Please sign in to comment.