Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda