Skip to content

Commit ec0a842

Browse files
committed
Allow importing files with MIME type "application/octet-stream"
Ported from FossifyOrg/Messages#137. Sometimes Android reports the MIME type as "application/octet-stream" even if the file has a .json extension (specifically, on Android 8 and 9 for backups exported outside the Download folder). Previously, such files could not be selected in the file picker when importing. As a workaround, allow files with that MIME type on Android < 10. Fixes #34.
1 parent 84cdfc4 commit ec0a842

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

app/src/main/kotlin/org/fossify/notes/activities/SettingsActivity.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ import kotlin.system.exitProcess
3232

3333
class SettingsActivity : SimpleActivity() {
3434
private val notesFileType = "application/json"
35+
private val notesImportFileTypes = buildList {
36+
add("application/json")
37+
if (!isQPlus()) {
38+
// Workaround for https://github.com/FossifyOrg/Notes/issues/34
39+
add("application/octet-stream")
40+
}
41+
}
42+
3543
private val binding by viewBinding(ActivitySettingsBinding::inflate)
3644

3745
override fun onCreate(savedInstanceState: Bundle?) {
@@ -89,12 +97,13 @@ class SettingsActivity : SimpleActivity() {
8997
return super.onCreateOptionsMenu(menu)
9098
}
9199

92-
private val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
93-
if (uri != null) {
94-
toast(org.fossify.commons.R.string.importing)
95-
importNotes(uri)
100+
private val getContent =
101+
registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
102+
if (uri != null) {
103+
toast(org.fossify.commons.R.string.importing)
104+
importNotes(uri)
105+
}
96106
}
97-
}
98107

99108
private val saveDocument = registerForActivityResult(ActivityResultContracts.CreateDocument(notesFileType)) { uri ->
100109
if (uri != null) {
@@ -315,7 +324,7 @@ class SettingsActivity : SimpleActivity() {
315324

316325
private fun setupNotesImport() {
317326
binding.settingsImportNotesHolder.setOnClickListener {
318-
getContent.launch(notesFileType)
327+
getContent.launch(notesImportFileTypes.toTypedArray())
319328
}
320329
}
321330

0 commit comments

Comments
 (0)