@@ -237,9 +237,6 @@ class MainActivity : SimpleActivity() {
237
237
override fun onActivityResult (requestCode : Int , resultCode : Int , resultData : Intent ? ) {
238
238
super .onActivityResult(requestCode, resultCode, resultData)
239
239
if (requestCode == PICK_OPEN_FILE_INTENT && resultCode == RESULT_OK && resultData != null && resultData.data != null ) {
240
- val takeFlags = Intent .FLAG_GRANT_READ_URI_PERMISSION or Intent .FLAG_GRANT_WRITE_URI_PERMISSION
241
- applicationContext.contentResolver.takePersistableUriPermission(resultData.data!! , takeFlags)
242
-
243
240
importUri(resultData.data!! )
244
241
} else if (requestCode == PICK_EXPORT_FILE_INTENT && resultCode == Activity .RESULT_OK && resultData != null && resultData.data != null && mNotes.isNotEmpty()) {
245
242
val takeFlags = Intent .FLAG_GRANT_READ_URI_PERMISSION or Intent .FLAG_GRANT_WRITE_URI_PERMISSION
@@ -625,9 +622,26 @@ class MainActivity : SimpleActivity() {
625
622
val content = inputStream?.bufferedReader().use { it!! .readText() }
626
623
val checklistItems = content.parseChecklistItems()
627
624
625
+ // if we got here by some other app invoking the file open intent, we have no permission for updating the original file itself
626
+ // we can do it only after using "Export as file" or "Open file" from our app
627
+ val canSyncNoteWithFile = if (hasPermission(PERMISSION_WRITE_STORAGE )) {
628
+ true
629
+ } else {
630
+ try {
631
+ val takeFlags = Intent .FLAG_GRANT_READ_URI_PERMISSION or Intent .FLAG_GRANT_WRITE_URI_PERMISSION
632
+ applicationContext.contentResolver.takePersistableUriPermission(uri, takeFlags)
633
+ true
634
+ } catch (e: Exception ) {
635
+ false
636
+ }
637
+ }
638
+
628
639
if (checklistItems != null ) {
629
640
val note = Note (null , noteTitle, content, NoteType .TYPE_CHECKLIST .value)
630
641
displayNewNoteDialog(note.value, title = noteTitle, setChecklistAsDefault = true )
642
+ } else if (! canSyncNoteWithFile) {
643
+ val note = Note (null , noteTitle, content, NoteType .TYPE_TEXT .value)
644
+ displayNewNoteDialog(note.value, title = noteTitle, " " )
631
645
} else {
632
646
val items = arrayListOf (
633
647
RadioItem (EXPORT_FILE_SYNC , getString(R .string.update_file_at_note)),
0 commit comments