Reputation: 71
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.
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
Upvotes: 3
Views: 2580
Reputation: 444
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
Upvotes: 0
Reputation: 59
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();
}
Upvotes: 5