Read Zip content on Android

Hi there, I want to read the content of a zip file on android using the ZipFile class but I get no content. Everything works as expected on the desktop version of the app.

What I do is getting the filepath to the zip file through filechooser and passing it to the ZipFile constructor.
I have also tried using the getURLResult from filechooser rather than getResult (in this attempt I then used url.getLocalFile() to have a file to feed to the ZipFile constructor ).

In both cases, zipFile.getNumEntries() gives an empty result (not even 0). What am I missing?

I found out the problem was a permission that needed to be granted.
Problem is I can’t use juce’s callback such as

juce::RuntimePermissions::request (juce::RuntimePermissions::readExternalStorage, [this] (bool granted) mutable {
                                { ...  }

as the permission needed, in my case, is to manage documents and not media files. The permission to read from external drives is not enough. I got it working by adding this line into the manifest xml file:

  <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>

and then prompting the user to go to settings and grant the needed permission to the app.

It would be handy if among the RuntimePermissions::PermissionID enum items there would be a ManageExternalStorage option…

1 Like