1

I have a request to make my application edit PDF files. Because I found it hard to integrate into the application, I decided to go with the external app and decided to use Xodo reader.

The problem I am having is that when my pdf is opened in the Xodo app and edited, it's not being saved to its original location, but rather a copy is saved to the Download folder. To me, this indicates that the app isn't able to save the edited file back to it's original destination, and I believe it's because I didn't do something right.

Why do I think this?

When Xodo app opens a .pdf file and then edits it when I hit back it saves it to the memory location it is opened from. When I load it with my app, it doesn't work that way.

Here is my code:

How I call the application

    val target = view?.packageManager?.getLaunchIntentForPackage("com.xodo.pdf.reader")
    target?.action = Intent.ACTION_EDIT
    target?.setDataAndType(FileProvider.getUriForFile(context, view?.applicationContext?.packageName + ".fileprovider", report.file), "application/pdf")
    target?.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
    target?.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION

    view?.startActivity(target)

What my @xml/provider_pathslooks like

<paths xmlns:android="http://schemas.android.com/apk/res/android">
     <external-path name="myApp" path="."/>
</paths>

Where my file is located in the memory

/Internal storage/myApp

What my content URI looks like

content://com.example.myapp.debug.fileprovider/myApp/myApp/example0.pdf

Does anybody have a clue what I am doing wrong and where?

Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45
Pavle37
  • 571
  • 9
  • 24

1 Answers1

2

Try granting both FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION. Right now, you are only granting read access, and so Xobo has no ability to write back to the provider.

Note that there is nothing that requires Xobo to write back to the provider, so even if you grant write access, Xobo may still write the modified PDF to a separate file.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491