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:
parent
8ee2186830
commit
19a154f57b
@ -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}"
|
||||
|
@ -1,8 +1,4 @@
|
||||
QT += network widgets
|
||||
android: qtHaveModule(androidextras) {
|
||||
QT += androidextras
|
||||
DEFINES += REQUEST_PERMISSIONS_ON_ANDROID
|
||||
}
|
||||
|
||||
HEADERS += httpwindow.h
|
||||
SOURCES += httpwindow.cpp \
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user