Skip to content

Commit

Permalink
Make it compatible on Android 6 devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
randy-yang authored Aug 29, 2019
1 parent 8b03e1c commit 27e4c22
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions android/src/main/java/com/rnziparchive/RNZipArchiveModule.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<? extends ZipEntry> entries = zipFile.entries();
Log.d(TAG, "Zip has " + zipFile.size() + " entries");
while (entries.hasMoreElements()) {
Expand Down Expand Up @@ -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<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
Expand Down

0 comments on commit 27e4c22

Please sign in to comment.