Android Question Loading/Displaying PDF in Webview with ContentChooser problem

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I want the user to be able to
  1. select a PDF file from their local storage,
  2. display a preview of the PDF file
  3. and then upload the file to a remote server.

I have all of this working fine with B4i using the code from https://www.b4x.com/android/forum/threads/b4x-texteditor-save-and-load-external-files.132731/ and multipart post. However, I have run into problems with B4A.

I have modified (slightly) the code from this tutorial to demonstrate the first part problem I am having:

I can select a file, however, I cannot then display it in a webview nor can I upload it using multipart post. Strangely, the ReadString function works fine.

I am using LoadUrl on the Webview to display the PDF.
B4X:
            WebView1.loadurl(xui.FileUri(Result.dir,Result.filename))
'            WebView1.loadurl(File.combine(Result.dir,Result.filename))

Page Finished show that the webview thinks it has loaded the file.

B4X:
private Sub webview1_PageFinished (Url As String)
    toast.show($"Finished loading ${Url}"$)
    Log($"Finished loading ${Url}"$)
End Sub
The commented out line just gives a file not found error.

Finished loading file://contentdir/content%3A%2F%2Fcom.android.providers.downloads.documents%2Fdocument%2F3197

Any ideas what I am doing wrong?

FYI I am testing on a Samsung Galaxy Tab A
 

Attachments

  • TextEditorwebview.zip
    184.4 KB · Views: 153

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
1. Android WebView doesn't support PDF documents.
2. Don't use FileUri with this url. Result.filename is the url.

Ah, that would explain it.

I try give PDFium to view the PDF instead, https://www.b4x.com/android/forum/threads/pdfium-pdfview2.102756/#post-644710, as I would prefer to have the PDF in a view rather than call an intent which would be full screen.

So using Multipart post to upload the file to a server,

is it ?
B4X:
    Dim mp As MultipartFileData
    mp.Initialize
    mp.Dir = result.dir
    mp.FileName = result.filename
 
Upvote 0
Top