Android Question [SOLVED] - Open ZIP file (selected with ContentChooser) fails

artsoft

Active Member
Licensed User
Longtime User
Hi!

I try to open a ZIP file which was selected by the ContentChooser. But it fails:

B4X:
Sub Process_Globals
    Public zipChooser As ContentChooser
End Sub

Sub handleImport()
    If (zipChooser.IsInitialized == False) Then
        zipChooser.Initialize("zipChooser")
    End If
    zipChooser.show("application/zip", "Please select zip file")
End Sub

Sub zipChooser_Result(Success As Boolean, Dir As String, FileName As String)
    If Success Then
        Private arc As Archiver
        Private out_tmp As String = File.Combine(File.DirInternal, "tmp_")
        File.MakeDir("", out_tmp)
        Private files_count As Int = arc.UnZip(Dir, FileName, out_tmp, "unzipping")
        Log(files_count)
    End If
End Sub

And I get always this exception:

java.io.IOException: java.io.FileNotFoundException: ContentDir/content:/com.alphainventor.filemanager.fileprovider/root/storage/emulated/0/Backup/PB-Backup.zip: open failed: ENOENT (No such file or directory)

Dir is : ContentDir/
FileName is: content:/com.alphainventor.filemanager.fileprovider/root/storage/emulated/0/Backup/PB-Backup.zip

SDK is >= 26

For FileProvider (which is used in my app) the manifest file is correctly set:

B4X:
AddApplicationText(
  <provider
        android:name="android.support.v4.content.FileProvider"
          android:authorities="$PACKAGE$.provider"
          android:exported="false"
          android:grantUriPermissions="true">
          <meta-data
                  android:name="android.support.FILE_PROVIDER_PATHS"
                  android:resource="@xml/provider_paths"
          />
  </provider>
)
'
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)

Who can help here?

Thanks in advance.

Regards
ARTsoft
 

artsoft

Active Member
Licensed User
Longtime User

Ok, I will try it and update this thread accordingly.
Thanks, Erel.

By the way .... the same procedure, I use for this ...

B4X:
Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)
    
    If Success Then
        Dim b as Bitmap = LoadBitmap(Dir, FileName)
    Else
        ...
    End If
    
End Sub

... and this works without any problems, with all bitmaps (in different folders) selected on my smartphone.

Is the LoadBitmap method able to handle Content-URLs as well?

Regards
 
Upvote 0

artsoft

Active Member
Licensed User
Longtime User
BINGO!!!! Now it works .....

I copy first the source content to my local file and then I can unzip the files:

B4X:
Private const zipName As String = "tmp.zip"
Private out_tmp As String = File.Combine(File.DirInternal, "tmp_")
File.MakeDir("", out_tmp)
' -----------------------------------------------------------------------------
Private in As InputStream = File.OpenInput(Dir, FileName)
Private out As OutputStream = File.OpenOutput(out_tmp, zipName, False)
' -----------------------------------------------------------------------------
File.Copy2 (in, out)
' -----------------------------------------------------------------------------
in.Close
out.Flush
out.close
' -----------------------------------------------------------------------------
If File.Exists(out_tmp, zipName) Then
    Private files_count As Int = arc.UnZip(out_tmp, zipName, out_tmp, "unzipping")
    Log(files_count)
End If

Thanks Erel!
Regards
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…