From c2398791bea09ec3874574e44ec5cedd776a2ff5 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 7 Mar 2024 13:44:25 +0000 Subject: [PATCH] ImageDemo: Fix permissions on mobile devices Co-authored-by: MajorMurphy --- examples/GUI/ImagesDemo.h | 20 +++++++++++++++++-- .../juce_core/native/juce_Files_android.cpp | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/GUI/ImagesDemo.h b/examples/GUI/ImagesDemo.h index 226a3e94c2..814c910262 100644 --- a/examples/GUI/ImagesDemo.h +++ b/examples/GUI/ImagesDemo.h @@ -56,8 +56,6 @@ public: ImagesDemo() { setOpaque (true); - imageList.setDirectory (File::getSpecialLocation (File::userPicturesDirectory), true, true); - directoryThread.startThread (Thread::Priority::background); fileTree.setTitle ("Files"); fileTree.addListener (this); @@ -81,6 +79,24 @@ public: -0.7); // and its preferred size is 70% of the total available space setSize (500, 500); + + RuntimePermissions::request (RuntimePermissions::readMediaImages, [self = SafePointer { this }] (bool granted) + { + if (self == nullptr) + return; + + if (! granted) + { + AlertWindow::showMessageBoxAsync (MessageBoxIconType::WarningIcon, + "Permissions warning", + "External storage access permission not granted, some files" + " may be inaccessible."); + return; + } + + self->imageList.setDirectory (File::getSpecialLocation (File::userPicturesDirectory), true, true); + self->directoryThread.startThread (Thread::Priority::background); + }); } ~ImagesDemo() override diff --git a/modules/juce_core/native/juce_Files_android.cpp b/modules/juce_core/native/juce_Files_android.cpp index b91e05339c..4f80de5e48 100644 --- a/modules/juce_core/native/juce_Files_android.cpp +++ b/modules/juce_core/native/juce_Files_android.cpp @@ -297,7 +297,7 @@ private: if (jniCheckHasExceptionOccurredAndClear()) { - // An exception has occurred, have you acquired RuntimePermission::readExternalStorage permission? + // An exception has occurred, have you acquired RuntimePermissions::readExternalStorage permission? jassertfalse; return {}; }