Xamarin-android: Android Webview cannot render the pdf sometimes and shows blank/white page instead

Created on 16 Apr 2019  路  16Comments  路  Source: xamarin/xamarin-android

Steps to Reproduce

  1. Open the pdf in the webview using google docs link.
  2. Open the same pdf or different pdf again and again.
  3. Sometimes it will show the blank/white page in the android untill we refresh the webpage again for 1 or 2 times.

    #

Code

public void SetWebView(WebView webview,string externalUrl){
            webview.Tag = "webview";
            webview.Settings.JavaScriptEnabled = true;
            webview.Settings.SupportZoom ();
            webview.Settings.SetAppCacheEnabled(true);
            webview.Settings.DomStorageEnabled = true;
            webview.ZoomOut ();
            webview.ZoomIn ();
            webview.Settings.BuiltInZoomControls = true;
            webview.Settings.LoadWithOverviewMode = true;
            webview.Settings.UseWideViewPort = true;
            //webview.Settings.SetSupportZoom (true);
            webview.Settings.SetPluginState (WebSettings.PluginState.On);
            webview.Settings.GetPluginState ();
            if (externalUrl.StartsWith("http://") || externalUrl.StartsWith("https://"))
                webview.LoadUrl (externalUrl);
            webview.SetWebViewClient (new MonkeyWebViewClient (imgViewBack, imgViewForward, imgRefresh));
            webview.SetWebChromeClient (new WebChromeClient ());
        `}`

Screenshot_20190416-132946 1

need-info

All 16 comments

Hello, @gopalawasthi123

Would you mind creating a small application to reproduce the issue? We'd also need more information about your environment, specifically:

  • Your Xamarin.Android version
  • Your operating system
  • Your IDE version
  • Android version you run the application on
  • Does it happen on device, in the emulator, both?

Thanks!

I will try to create a small application to reproduce the same issue. As per your need I send the information about the environment below:

  • Xamarin.Android Version => 2.5144934
  • Operating System => Windows
  • IDE Version => Microsoft Visual Studio Community 2017 Version 15.9.2
  • Android Version - 26
  • I checked it only on device in fact on 3 or more devices.

Same issue with me also

Let me know if you get a sample, the Android Device log recorded when the problem occurred would also help.

Command-line is probably the easiest way: adb logcat -d > log.txt

Hi @jonathanpeppers , @grendello
I have made the sample on the pdf. The link for the project is shown below:
https://github.com/gopalawasthi123/PdfWebView
Hope this will help you Better.

@gopalawasthi123 I see lots of errors when the web view tries to load the page in your sample:

04-29 11:07:49.997 W/cr_media( 8003): Requires BLUETOOTH permission
04-29 11:07:50.070 W/VideoCapabilities( 8003): Unrecognized profile 2130706433 for video/avc
04-29 11:07:50.071 W/VideoCapabilities( 8003): Unrecognized profile 2130706434 for video/avc
04-29 11:07:50.072 W/VideoCapabilities( 8003): Unrecognized profile 2130706433 for video/avc
04-29 11:07:50.072 W/VideoCapabilities( 8003): Unrecognized profile 2130706434 for video/avc
04-29 11:07:50.081 D/NetworkSecurityConfig( 8003): No Network Security Config specified, using platform default
04-29 11:07:50.082 W/VideoCapabilities( 8003): Unrecognized profile 2130706433 for video/avc
04-29 11:07:50.082 W/VideoCapabilities( 8003): Unrecognized profile 2130706434 for video/avc
04-29 11:07:50.089 W/VideoCapabilities( 8003): Unrecognized profile 4 for video/hevc
04-29 11:07:50.102 W/VideoCapabilities( 8003): Unrecognized profile 4 for video/hevc

So two questions:

  • Does the page render in the regular browser? Like if you open Chrome and navigate to the URL?
  • Does a similar Android Studio/Java-only sample work?

Xamarin.Android just surfaces the Android APIs to C# as-is. I suspect you would hit the same problem with Java? I don't know there is anything we can do in Xamarin.Android to fix this issue?

@jonathanpeppers :
Yes the Page Renders fines if we open in a regular Browser.
Yes It behaves the same in Android Studio.

If you're getting the same problem in Android Studio, that means it's probably just a general problem with Android, sorry 馃槥 .

I think you should try posting on either:

Closing for now, since I don't think it's an issue with Xamarin.Android, but let us know otherwise, thanks!

This might have to do with the issue I am facing, uninstall all chrome updates on your phone. And open the webview, it will function properly. Chrome update after 69 broke Xamarin Webview for Android.

@jonathanpeppers
Thanks Man. I will post this bug on the Google's Bug Tracker. I already have posted this on the Stack Overflow

@keyur-apa
Do you have any solution to this Chrome Issue with the pdf i am facing

@gopalawasthi123 I do not, but to my problem, my other app developed via Ionic 3 works fine with webview & latest chrome on android on pdf links. It is just Xamarin Forms App with chrome 69+

@keyur-apa No I made a sample also on the android studio. It also have a same issue as in the xamarin android

I am still facing this issue in android studio

@anilkumar416 you can solve this issue by using JSPDF on the serverside from mobile side you can do nothing.

I was able to solve this https://medium.com/@mr.kante416/pdf-in-webview-android-1380de57155c shared in this article now well written will update in some time.

Was this page helpful?
0 / 5 - 0 ratings