Domanda

I am trying to code in C# with DOT42. How do I navigate to an html inside my Assets folder. I have achieved the same wit Eclipse in java with the following Code:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String url = "http://www.google.com";
    url="file:///android_asset/out/in/active_deals.html";        
    WebView webv = (WebView) findViewById(R.id.webview1);
    WebSettings settings = webv.getSettings();
    settings.setJavaScriptEnabled(true);
    webv.setWebViewClient(new WebViewClient());
    webv.loadUrl(url);
}

When I try to do the same in C# with DOT42, it says page not found:

protected override void OnCreate(Bundle savedInstance)
    {
        base.OnCreate(savedInstance);
        SetContentView(R.Layouts.MainLayout);

        base.OnCreate(savedInstance);
        SetContentView(R.Layouts.MainLayout);
        string url = "";
        //url = "http://www.google.com";
        url = "file:///Android_Asset/out/in/active_deals.html";
        WebView myWebView = (WebView)FindViewById(R.Ids.webview1);
        myWebView.SetWebViewClient(new WebViewClient());
        myWebView.LoadUrl(url);
        WebSettings webSettings = myWebView.GetSettings();
        webSettings.SetJavaScriptEnabled(true);

    }

I have tried naming the assets folder in lower case and upper case, both don't seem to work. I have tried 'Android_Asset','android_asset','Asset' but none of it worked. It works with eclipse though.

È stato utile?

Soluzione

When you add an embedded resource to your Visual Studio project, it will be converted to an asset in your APK with the full namespace name.

For example take this URL:

var url = "file:///android_asset/dot42AssetWebView.Resources.Index.htm";

It works fine for an embedded resource named Index.htm in a namespace "dot42AssertWebView.Resources".

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top