3
votes

I have uploaded a Pdf file to firebase storage, after uploading the pdf file to firebase storage, I am getting the download url. Now I want to open the pdf file in webview in my android application.

Below is the url I am getting after uploading the pdf file to firebase storage.

https://firebasestorage.googleapis.com/v0/b/onecoach-256129.appspot.com/o/admin%2F1513215604514.pdf?alt=media&token=059d1d8a-6ee9-42df-9b08-3e126e192d10

Below is my method for open pdf in webview

private void loadWebUrl(String url) {
    myWebView.setBackgroundColor(Color.TRANSPARENT);
    myWebView.getSettings().setJavaScriptEnabled(true);
    settings.setAllowFileAccessFromFileURLs(true);
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setBuiltInZoomControls(true);
    //url = "http://narsun.pk/profile.pdf";
    if (url!=null&&!url.isEmpty()) {
        myWebView.loadUrl("https://docs.google.com/viewerng/viewer?url="+url);
        //myWebView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url="+url);
    }else {
        Utils.showToast(mActivity,"Sorry No Pdf url Exist!");
        mActivity.onBackPressed();
    }
}

Please help me where I am wrong! Thanks

2

2 Answers

4
votes

Late but you should encode your url,

try {
    url=URLEncoder.encode(url,"UTF-8");
    myWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+url);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}
0
votes

I think your problem when you upload the file to firebase, you should add metadata of your uploaded file in you case you should define StorageMetadata and set contentType of "application/pdf"

This code from iOS app

FIRStorageMetadata* metadata = [[FIRStorageMetadata alloc] init];
metadata.contentType = @"application/pdf";

and then when you put data to firebase add this metadata in upload function