Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:45:38+00:00 2026-05-31T11:45:38+00:00

My current monodroid project is having two problems – one in loading from Assets

  • 0

My current monodroid project is having two problems – one in loading from Assets and the other is a generated webpage being passed to be displayed and their inter-related which makes things more annoying!

The assets problem is simple enough, the file can’t be found. My current code looks like this

Android.App.Application.SynchronizationContext.Post(delegate
{
    string uri = "file:///android_asset/StyleSheet.css";
    string settings = string.Empty;

    using (var input = c.Assets.Open(uri))
    using (StreamReader sr = new System.IO.StreamReader(input))
    {
         settings = sr.ReadToEnd();
    }

    string CSS = "<html><head><style>" + settings + "</style></head><body style='height:600px;background: url(Back-AQHA.jpg)' >";
    retStr = CSS + tableData.Content + "</body></html>";
    callback(retStr);
}, null);

This dies at the sr.ReadToEnd() line as the file can’t be found. All the permissions are correctly set for me to be able to access the assets directory and read in.

c is just a Context passed to the method

Now, assuming that the file had be read in and passed back to the caller, it now fails to be displayed (tested this by generating a page within the app and passing it back)… The webviewer code is bog standard

public class webservice_webview : Activity
{
    WebView web_view;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.webview);
        string res = base.Intent.GetStringExtra("content");
        if (res.Length > 0)
        {
            web_view = FindViewById<WebView>(Resource.Id.webviewer);
            web_view.Settings.JavaScriptEnabled = true;
            web_view.LoadData(res, "text/html", null);
            web_view.SetWebViewClient(new websiteviewClient());
        }
        else
            return;
    }

    private class websiteviewClient : WebViewClient
    {
        public override bool ShouldOverrideUrlLoading(WebView view, string url)
        {
            view.LoadData(url, "text/html", null);
            return true;
        }
    }

    public override bool OnKeyDown(Android.Views.Keycode keyCode, Android.Views.KeyEvent e)
    {
        if (keyCode == Keycode.Back && web_view.CanGoBack())
        {
            web_view.GoBack();
            return true;
        }

        return base.OnKeyDown(keyCode, e);
    }
}
}

When the content is passed over and rendered, all that results is a dead webpage saying that the url data;text/html;null,[generated html] may have moved or has gone. How do I get the generated page to display?

Thanks

Paul

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:45:40+00:00Added an answer on May 31, 2026 at 11:45 am

    It might be worth check your assets are in the assets folder and are marked in the properties pane as being “AndroidAsset” – also please make sure capitalisation is correct.

    Assuming they are then you can just pass the assets direct to the webview using code like:

            var web = FindViewById<WebView>(Resource.Id.AboutWebView);
            web.LoadUrl("file:///android_asset/About/index.html");
    

    from https://github.com/slodge/mobile-samples/blob/master/MWC/MWC.Droid/Views/About/AboutXamarinView.cs

    If you do want to read in and manipulate the html text first, then try code like: Assets.Open("About/index.html") – i.e. without the file: scheme attached.

    In your second sample, the code for web_view.LoadData(res, "text/html", null); looks correct – but then I’m not sure what your logic inside ShouldOverrideUrlLoading does – that looks like it might just prevent things from loading?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Current state: I have a tray icon, two context menus - one for about/options/exit/etc.
Current project: To make a time program in C# with two classes Time and
My current development project has two aspects to it. First, there is a public
My current project is in Rails. Coming from a Symfony (PHP) and Django (Python)
Current situation: Ubuntu 8.04 server edition (live server) Postgresql 8.3.7 (from standard repositories) Postgis
Current static source analysis tools for C# (or other .NET languages) usually operate on
My monodroid application builds and runs fine, but breakpoints are not being hit. This
Current Project Setup I've been working on a web-based chat, similar to Facebook chat.
Current, I have a parent CWnd, which is displaying many other child CWnds. All
Current Code: WHERE EXTRACT(YEAR_MONTH FROM timestamp_field) = EXTRACT(YEAR_MONTH FROM now())) Instead of EXTRACT(YEAR_MONTH FROM

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.