Open l3utterfly opened 2 months ago
Is it working on android 7.0?
https://developer.android.com/reference/java/nio/file/package-summary
Added in API level 26 java.nio.file
I previously added this API but changed to FileChannel because we need to support android 7.0+ (api 24+)
Hmm.. my app has min version 26 so this was not a problem.
How about this code?
private static void moveFile(File src, File dst) throws IOException {
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
try {
long bytesTransferred = 0;
long totalBytes = inChannel.size();
while (bytesTransferred < totalBytes) {
long remainingBytes = totalBytes - bytesTransferred;
long chunkSize = Math.min(remainingBytes, Integer.MAX_VALUE);
long transferredBytes = inChannel.transferTo(bytesTransferred, chunkSize, outChannel);
bytesTransferred += transferredBytes;
}
src.delete();
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
(untested, but should work). The main problem with the previous code is that transferTo
takes an Int
, which cannot go past 2GB
Could you test in android emulator with api 24?
I can do it also but on Wednesday.
Not able to download files above 1GB . Please provide fix for this
Did you try the code in the PR? I tested it and it works for files over 4GB with no problems
I tried code from PR still same issue
Hmm.. not sure, will take a look later. The code works fine, and it is already in production, so not sure what's wrong with your version
Critical issue in android for copying large files: previous version downloads the large file but does not copy anything over 2GB.
Sorry! This PR fixes it.