Alexander Toman Alexander Toman - 1 year ago 116
Java Question

On rendering PDF and modifying Uri

I am trying to render PDF link using a webview. The link I am trying to render, is uploaded by my app to the firebase database.

While the link is rendered succesffuly on the iOS devices. It isn't on the Android.

I greatly speculate the reason behind all this confusion to be the firebase link .

If I try to render a normal pdf link from the web.

String pdf_sample = "";
String googleDocs = "";

Webviewz.loadUrl(googleDocs + pdf_sample);

Resulting in succesful PDF rendering

image -SUCCESSSFULLY- displaying a normal PDF Url

If however I rely and attempt to display and render a PDF link from my Firebase database, I get this blank dark gray background by google docs and a sign of NO PREVIEW AVAILABLE

String Firebase_link_failure = "";
String googleDocs = "";

Webviewz.loadUrl(googleDocs + Firebase_link_failure);

Resulting in No Preview Available

image -FAILURE- displaying a Firebase PDF link on android devices

The solution suggested by the user sphippen worked out. Using the UrlEncoder on the firebase link, The pdf was successfully rendered. Below is the single modification made.

Webviewz.loadUrl(googleDocs+ URLEncoder.encode(firebase_link, "utf-8"));

Answer Source

It looks like the problem is that you're just appending two strings to form your URL:

Webviewz.loadUrl(googleDocs + pdf_sample);

Looking at the full URL (using the values from your code sample):

The & character after alt=media ends the url parameter, so the URL the page tries to access is just, which doesn't contain the download token.

You'll need to escape the Firebase Storage download link for use as a URL parameter (replacing & with %26, ? with %3F, % with %25, etc.). The URLEncoder class should work:

URLEncoder.encode(pdf_sample, "UTF-8")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download