mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
fix copying files to sd card
This commit is contained in:
@ -1,15 +1,14 @@
|
|||||||
package com.simplemobiletools.filemanager.asynctasks
|
package com.simplemobiletools.filemanager.asynctasks
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.support.v4.util.Pair
|
import android.support.v4.util.Pair
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import java.io.File
|
import com.simplemobiletools.filemanager.Utils
|
||||||
import java.io.FileInputStream
|
import java.io.*
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.IOException
|
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
class CopyTask(listener: CopyTask.CopyListener) : AsyncTask<Pair<List<File>, File>, Void, Boolean>() {
|
class CopyTask(listener: CopyTask.CopyListener, val context: Context) : AsyncTask<Pair<List<File>, File>, Void, Boolean>() {
|
||||||
private val TAG = CopyTask::class.java.simpleName
|
private val TAG = CopyTask::class.java.simpleName
|
||||||
private var mListener: WeakReference<CopyListener>? = null
|
private var mListener: WeakReference<CopyListener>? = null
|
||||||
private var destinationDir: File? = null
|
private var destinationDir: File? = null
|
||||||
@ -52,7 +51,14 @@ class CopyTask(listener: CopyTask.CopyListener) : AsyncTask<Pair<List<File>, Fil
|
|||||||
}
|
}
|
||||||
|
|
||||||
val inputStream = FileInputStream(source)
|
val inputStream = FileInputStream(source)
|
||||||
val out = FileOutputStream(destination)
|
var out: OutputStream?
|
||||||
|
if (Utils.needsStupidWritePermissions(context, destination.absolutePath)) {
|
||||||
|
var document = Utils.getFileDocument(context, destination.absolutePath)
|
||||||
|
document = document.createFile("", destination.name)
|
||||||
|
out = context.contentResolver.openOutputStream(document.uri)
|
||||||
|
} else {
|
||||||
|
out = FileOutputStream(destination)
|
||||||
|
}
|
||||||
|
|
||||||
val buf = ByteArray(1024)
|
val buf = ByteArray(1024)
|
||||||
var len: Int
|
var len: Int
|
||||||
@ -60,7 +66,7 @@ class CopyTask(listener: CopyTask.CopyListener) : AsyncTask<Pair<List<File>, Fil
|
|||||||
len = inputStream.read(buf)
|
len = inputStream.read(buf)
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
break
|
break
|
||||||
out.write(buf, 0, len)
|
out!!.write(buf, 0, len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class CopyDialog(val activity: Activity, val files: List<File>, val path: String
|
|||||||
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
||||||
Utils.showToast(context, R.string.copying)
|
Utils.showToast(context, R.string.copying)
|
||||||
val pair = Pair<List<File>, File>(files, destinationDir)
|
val pair = Pair<List<File>, File>(files, destinationDir)
|
||||||
CopyTask(copyListener).execute(pair)
|
CopyTask(copyListener, mContext).execute(pair)
|
||||||
dismiss()
|
dismiss()
|
||||||
} else {
|
} else {
|
||||||
for (f in files) {
|
for (f in files) {
|
||||||
|
Reference in New Issue
Block a user