Skip to content

Commit 4142e96

Browse files
authored
Merge pull request #92 from tom93/pr/fix-import-binary-mime-type
Allow importing files with MIME type "application/octet-stream"
2 parents 84cdfc4 + ec0a842 commit 4142e96

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

+15-6
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)