Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
Local HTML file does not show properly in WebView with Xamarin.Forms

I have a simple HTML file:

<html>
  <head>
    <script async src="https://URL"></script>
  </head>
  <body>
    <div class="class-name"></div>
  </body>
</html>

When I access it with a browser using Windows: C:\foo.html?q=query the file loads correctly.

When I access the same file, that I have added it to my Android project in the Assets directory, with a Custom WebView and a Custom Renderer in my Xamarin.Forms project like this: myCustomWebview.Uri = "foo.html" + "?q=" + queryString; the Javascript fails to populate the div in the body correctly. The same problem exists if I load the file without a query string: myCustomWebview.Uri = "foo.html";

What's the deal? Do I need to set any special Permissions in the AndroidManifest.xml for the Javascript to work properly? Do I need to set a specific BuildAction in the file properties of the HTML file in my Android project? Do I need to do something else?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. Place html file into Assets directory with build action AndroidAsset .

  2. Use DependencyService to set the exact path .

    [assembly: Dependency (typeof(BaseUrl_Android))]
    namespace WorkingWithWebview.Android
    {
        public class BaseUrl_Android : IBaseUrl
        {
            public string Get()
            {
                return "file:///android_asset/";
            }
        }
    }
    
  3. Set BaseUrl to HtmlWebViewSource and pass it to WebView.Source .

    var source = new HtmlWebViewSource();
    source.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
    webView.Source  = source .
    

Refer to

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows#local-html-content.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda