Skip to content

Commit b79bcb0

Browse files
committed
Fix compatibility with older Android versions
1 parent ce0856a commit b79bcb0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

app/src/main/java/dev/zwander/installwithoptions/MainActivity.kt

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
133133
super.onDestroy()
134134

135135
permissionHandler.onDestroy()
136+
cacheDir.deleteRecursively()
136137
}
137138

138139
private fun checkIntentForPackage(intent: Intent) {

app/src/main/java/dev/zwander/installwithoptions/util/IncomingPackageUtils.kt

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ fun Context.handleIncomingUris(uris: List<Uri>) {
1515
val currentSelection = DataModel.selectedFiles.value.toMutableMap()
1616

1717
fun addApkFile(file: DocumentFile) {
18-
val fd = contentResolver.openAssetFileDescriptor(file.uri, "r") ?: return
19-
val apkFile = PackageParser.parseApkLite(fd.fileDescriptor, file.name, 0)
18+
val realFile = if (file.uri.scheme == "file") file else run {
19+
contentResolver.openInputStream(file.uri).use { input ->
20+
val dest = File(cacheDir, "${file.name ?: file.uri}")
21+
dest.outputStream().use { output ->
22+
input.copyTo(output)
23+
}
24+
DocumentFile.fromFile(dest)
25+
}
26+
}
27+
val apkFile = PackageParser.parseApkLite(File(realFile.uri.path), 0)
2028
val packageList = currentSelection[apkFile.packageName] ?: listOf()
2129

2230
currentSelection[apkFile.packageName] = (packageList + file).distinctBy { "${apkFile.packageName}:${it.name}" }
23-
24-
fd.close()
2531
}
2632

2733
uris.forEach { uri ->

0 commit comments

Comments
 (0)