mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
fix selecting file on Android
This commit is contained in:
@@ -9,6 +9,7 @@ import android.net.Uri
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
|
import android.util.Log
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import androidx.activity.result.ActivityResultCallback
|
import androidx.activity.result.ActivityResultCallback
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
@@ -324,8 +325,25 @@ class MainActivity : FlutterFragmentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// use copy method
|
// use copy method
|
||||||
val filePath = FileUtils.getPathFromCopyOfFileFromUri(this, uri)
|
val tmp = File(cacheDir, fileName)
|
||||||
result.success(filePath)
|
if(tmp.exists()) {
|
||||||
|
tmp.delete()
|
||||||
|
}
|
||||||
|
Log.i("Venera", "copy file (${fileName}) to ${tmp.absolutePath}")
|
||||||
|
Thread {
|
||||||
|
try {
|
||||||
|
contentResolver.openInputStream(uri)?.use { input ->
|
||||||
|
FileOutputStream(tmp).use { output ->
|
||||||
|
input.copyTo(output, bufferSize = DEFAULT_BUFFER_SIZE)
|
||||||
|
output.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.success(tmp.absolutePath)
|
||||||
|
}
|
||||||
|
catch (e: Exception) {
|
||||||
|
result.error("copy error", e.message, null)
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user