From 27e4c22e4e1be1b37a8113b8164d00b34b5ac581 Mon Sep 17 00:00:00 2001 From: Randy Yang Date: Thu, 29 Aug 2019 14:52:00 +0800 Subject: [PATCH] Make it compatible on Android 6 devices. --- .../com/rnziparchive/RNZipArchiveModule.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/rnziparchive/RNZipArchiveModule.java b/android/src/main/java/com/rnziparchive/RNZipArchiveModule.java index d624b6a..d201c84 100644 --- a/android/src/main/java/com/rnziparchive/RNZipArchiveModule.java +++ b/android/src/main/java/com/rnziparchive/RNZipArchiveModule.java @@ -1,6 +1,7 @@ package com.rnziparchive; import android.content.res.AssetFileDescriptor; +import android.os.Build; import android.util.Log; import com.facebook.react.bridge.Arguments; @@ -141,7 +142,13 @@ public void run() { final long[] extractedBytes = {0}; final int[] lastPercentage = {0}; - final ZipFile zipFile = new ZipFile(zipFilePath, Charset.forName(charset)); + ZipFile zipFile = null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + zipFile = new ZipFile(zipFilePath, Charset.forName(charset)); + } else { + zipFile = new ZipFile(zipFilePath); + } + final Enumeration entries = zipFile.entries(); Log.d(TAG, "Zip has " + zipFile.size() + " entries"); while (entries.hasMoreElements()) { @@ -434,7 +441,12 @@ protected void updateProgress(long extractedBytes, long totalSize, String zipFil private long getUncompressedSize(String zipFilePath, String charset) { long totalSize = 0; try { - ZipFile zipFile = new ZipFile(zipFilePath, Charset.forName(charset)); + ZipFile zipFile = null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + zipFile = new ZipFile(zipFilePath, Charset.forName(charset)); + } else { + zipFile = new ZipFile(zipFilePath); + } Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement();