Android Question FileProvider path change

Peter Lewis

Active Member
Licensed User
Longtime User
Hi

I have followed the fileprovider tutorial by @Erel and changed the Manifest file to exactly what is in the example.

I then tried to load a pdf file with this code

B4X:
    Dim in As Intent
                in.Initialize(in.ACTION_VIEW, "")
                Starter.Provider.SetFileUriAsIntentData(in, filename)
                in.SetType("application/pdf")
                StartActivity(in)
Where filename has no path

then I tried it like this

B4X:
Dim pdffile As String = Main.pdffolder&filename
            Log(pdffile)
         
         
                Dim in As Intent
                in.Initialize(in.ACTION_VIEW, "")
                Starter.Provider.SetFileUriAsIntentData(in, pdffile)
                in.SetType("application/pdf")
                StartActivity(in)

and the file and path is

/storage/emulated/0/Android/data/b4a.chat/files\pdf\AC176F06-875F-B44A-8A5E-725D2DFA7BAB.pdf

the main.pdffolder is

B4X:
    Public pdffolder As String = File.DirDefaultExternal&"\pdf\"

where my pdf files do arrive . I have checked the file by going directly to it and opening it and it opens.

At the moment all what happens it is goes to the app to open the pdf and then displays the filename and close back to my app

I also tried making the files path in manifest to my path

B4X:
  <files-path name="name" path= DirDefaultExternal&"/pdf" />

but that fails on Compile

According to@Erel's post the active folder is

files-path = File.DirInternal

how can I change this to File.DirDefaultExternal

In my app all data is sent to these folders where I read from and write to

B4X:
 shared = Starter.rp.GetSafeDirDefaultExternal("")
 
     Main.imagefolder=shared&"\images\"
     Main.pdffolder = shared&"\pdf\"
     Main.profilefolder  = shared&"\profiles\"
     Main.thumbnailfolder  =shared&"\thumbnails\"

Please off any advise where to look next

Thank you
 
Last edited:

Peter Lewis

Active Member
Licensed User
Longtime User
Code with File.DirDefaultExternal = broken code.
Use rp.GetSafeDirDefaultExternal instead.

With that said, I don't understand what you are trying to do. Run the example as-is: https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/
Do you get any problem?
No , that works perfectly .BUT. I want to be also to use the phone explorer to access these files , if possible under Gallery. This I could not achieve so I made the folders under File.DirDefaultExternal . the PDF file will be under there in that structure. But It will not open because your example is under the Internal Hidden folder i cannot find ( File.DirInternal )

In the example I searched for b4a.png on my phone and CANNOT find it. This must be due to it been in the protected DirInternal Folder. Having files in there does not solve my problem.

I just looked into my code and the code i had there was in Main. In The initial default load I had

B4X:
 shared = Starter.rp.GetSafeDirDefaultExternal("")

     Main.imagefolder=shared&"\images\"
     Main.pdffolder = shared&"\pdf\"
     Main.profilefolder  = shared&"\profiles\"
     Main.thumbnailfolder  =shared&"\thumbnails\"


Now it gives me an error because it is going to the DirInternal Folder

java.io.FileNotFoundException: 5F18B498-DB23-4028-8328-A6F8214C6998.jpg (Read-only file system)

I think the question i am asking is the same as in #1


According to@Erel's post the active folder is

files-path = File.DirInternal
how can I change this to GetSafeDirDefaultExternal


Thank you
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top