0

Error description:

File does not exist: content:/com.alphainventor.filemanager.fileprovider/root/storage/emulated/0/Bollywood%20Mix/Old/Audio.mp3

I am using below dependency to create zip file:

implementation 'net.lingala.zip4j:zip4j:2.9.0'

Code used is as below:

fun zipAudios(context: Context, fileUrls: ArrayList<String>): File? {

        val zipfileCreated = createFile(
            getOutputDirectory(context),
            "yyyy-MM-dd-HH-mm-ss-SSS",
            ".zip"
        )

        // Create a buffer for reading the files
        try {
            // create the ZIP file
            val zipfile = ZipFile(zipfileCreated, null)

            for (i in fileUrls.indices) {
                zipfile.addFile(File(fileUrls[i]))
            }

            return zipfile.file
        } catch (ex: IOException) {
            System.err.println(ex.message)
        }
        return null
    }
  1. My App is selecting the audio from device using any available selector App and save its URL to play it.
  2. Audio file are able to play using MediaPlayer but I am not able to access it while creating .zip file for these audio files.

I have some questions regarding the same:

  1. Our URL has content URL format with selector App provider prefix like content:/com.alphainventor.filemanager.fileprovider/root/storage/emulated/0/Bollywood%20Mix/Old/Audio.mp3 How can I access such audio files and create zip from it on Android 10 programatically?
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Pradip Tilala
  • 1,715
  • 16
  • 24
  • You access them to open an inputstream for the uri and then read from the stream. Of course you should never use the File class for content scheme uries. – blackapps Nov 06 '21 at 07:52
  • `val zipfile` Pretty confusing that you define that twice. – blackapps Nov 06 '21 at 07:55
  • 1
    So look if you can replace `zipfile.addFile(File(fileUrls[i]))` with something like `zipfile.addFileFromUri(fileUrls[i])`. – blackapps Nov 06 '21 at 08:04
  • Thanks @blackapps. it worked using inputstream ------> ```for (i in fileUrls.indices) { val inputStream: InputStream? = context.getContentResolver().openInputStream(Uri.parse(fileUrls[i])) val zipParameters = ZipParameters() zipParameters.fileNameInZip = "" + File(fileUrls[i]).name zipfile.addStream(inputStream,zipParameters) }``` – Pradip Tilala Nov 06 '21 at 08:54

0 Answers0