Skip to content

Commit

Permalink
Added read storage permission request before show images
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsinSoft committed Aug 3, 2023
1 parent 4e8789c commit 2426264
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions QtAndroidToolsDemo/tools/AndroidImages.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import QtQuick
import QtQuick.Controls.Material
import QtAndroidTools
import Qt.labs.platform

Page {
id: page
Expand All @@ -16,9 +17,25 @@ Page {
}
}

Component.onCompleted: {
albumsNameList = QtAndroidImages.getAlbumsList();
showAlbumsImages(0);
Component.onCompleted: permission.requestPermission("android.permission.READ_EXTERNAL_STORAGE")

QtAndroidAppPermissions {
id: permission
onRequestPermissionsResults: function(results)
{
if(results[0].granted === true)
{
albumsNameList = QtAndroidImages.getAlbumsList();
showAlbumsImages(0);
}
else
{
if(permission.shouldShowRequestPermissionInfo(results[0].name) === true)
{
requestPermissionREAD_EXTERNAL_STORAGE.open();
}
}
}
}

Rectangle {
Expand Down Expand Up @@ -67,4 +84,12 @@ Page {
cache: false
}
}

MessageDialog {
id: requestPermissionREAD_EXTERNAL_STORAGE
buttons: MessageDialog.Ok
title: "Advise"
text: "This app require READ_EXTERNAL_STORAGE permission to read images from device"
onAccepted: permission.requestPermission("android.permission.READ_EXTERNAL_STORAGE")
}
}

0 comments on commit 2426264

Please sign in to comment.