7

I use webVIew read local HTML. HTML storage location Project for asset

Some phones can be successfully used(samsung...) Some phones can not(HTC nexus...)

Here is my code

public class MainActivity extends Activity {
    private WebView wvBrowser; 

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        findViews();
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (wvBrowser.canGoBack() && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            wvBrowser.goBack();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    private void findViews() {
        wvBrowser = (WebView) findViewById(R.id.Browser);

        //wvBrowser.loadUrl(getString(R.string.googleUrl));

        wvBrowser.getSettings().setSupportZoom(true);
        wvBrowser.getSettings().setBuiltInZoomControls(true);
        wvBrowser.loadUrl("file:///android_asset/ts.htm");      
    }   
}
seaplain
  • 771
  • 7
  • 25
HLto Dm
  • 275
  • 2
  • 5
  • 13

2 Answers2

8

Just wanted to add one more answer. Someone might find my suggestion helpful. You need to add uses-permission in your AndroidManifest.xml. I got similar error fixed by adding this line

<uses-permission android:name="android.permission.INTERNET" />
Praishgm
  • 131
  • 2
  • 10
3

Try this link it will help you better webview

Attach a WebViewClient to your WebView, where you override onReceivedError()

webview.setWebViewClient(new WebViewClient() {
       public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

       }
     });
Janmejoy
  • 2,721
  • 1
  • 20
  • 38