1
0
mirror of https://github.com/fumiama/android-base16384.git synced 2026-06-19 18:30:26 +08:00
1. 修复 生成大文件卡顿
This commit is contained in:
fumiama
2021-03-13 22:45:37 +08:00
parent 6f531d3b77
commit 5deabc23db
5 changed files with 13 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ android {
minSdkVersion 23
targetSdkVersion 30
versionCode 10
versionName '2.1'
versionName '2.1.1'
resConfigs "zh", "en"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Binary file not shown.

Binary file not shown.

View File

@@ -11,7 +11,7 @@
"type": "SINGLE",
"filters": [],
"versionCode": 10,
"versionName": "2.1",
"versionName": "2.1.1",
"outputFile": "app-release.apk"
}
]

View File

@@ -67,7 +67,10 @@ class MainActivity : Activity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK) when (requestCode) {
1 -> data?.data?.let { doFromFile(it) }
1 -> data?.data?.let {
Toast.makeText(this, "${getString(R.string.output)}...", Toast.LENGTH_SHORT).show()
doFromFile(it)
}
2 -> data?.data?.let { save2Uri(it) }
}
}
@@ -105,7 +108,7 @@ class MainActivity : Activity() {
fd?.close()
}
private fun save2Uri(uri: Uri){
private fun save2Uri(uri: Uri) = Thread{
val outputFile = generateCacheFile("output")
contentResolver.openOutputStream(uri)?.let {
val fi = outputFile.inputStream()
@@ -113,15 +116,18 @@ class MainActivity : Activity() {
fi.close()
it.close()
}
}
runOnUiThread {
Toast.makeText(this, "${getString(R.string.share)} ${getString(R.string.succeed)}", Toast.LENGTH_SHORT).show()
}
}.start()
private fun createFile(fileName: String, type: String = "*/*"){
private fun createFile(fileName: String, type: String = "*/*") = Thread{
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = type
intent.putExtra(Intent.EXTRA_TITLE, fileName)
startActivityForResult(intent, 2)
}
}.start()
private fun pickFile() {
val i = Intent(Intent.ACTION_GET_CONTENT)