Ted Betz
Ted Betz

Reputation: 1621

Webview loads html in android 2.2 but not android 2.1

I have a simple webview used to load a file help3.html when a user picks a HELP menu button.

The file loads and views well in an android 2.2 (8) emulator, but I get a "file //android_res/raw/help3.html not found" error message with an Android 2.1 (7) emulator.

I am assuming that there is code in the java or xml files that version 2.1 doesn't like, and the file not found error is a fluke.

My java code to load the html file:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;


public class Help extends Activity   
{   @Override  
    public void onCreate(Bundle savedInstanceState)  
    {   super.onCreate(savedInstanceState);  
    setContentView(R.layout.helpview);  
    WebView mywebview = (WebView)findViewById(R.id.webviewHelp);  
    mywebview.loadUrl("file:///android_res/raw/help3.html");  
    }       
}  

and my helpview.xml file is:

<?xml version="1.0" encoding="utf-8"?>  

<WebView xmlns:android="http://schemas.android.com/apk/res/android"  
android:id="@+id/webviewHelp"   
android:layout_width="fill_parent"  
android:layout_height="fill_parent"/>  

I'm stumped. Any ideas why this isn't working?

Upvotes: 1

Views: 1902

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007276

I was not aware that file:///android_res is valid in any version of Android.

If you put your HTML in your project's assets/ folder, you can use file:///android_asset as a prefix. This sample project demonstrates this.

Upvotes: 2

Related Questions