Android web browser error not found

I am using webVIew to read local HTML. HTML storage location Project for asset

Some phones can be used successfully (samsung ...) Some phones cannot (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"); } } 
+6
source share
3 answers

this solution is for you

According to the documentation and my experience, it should work well. You just need to set WebClient with override onReceivedError method in WebView .

Here is a snippet from my old test application:

  wvBrowser = (WebView) findViewById(R.id.Browser); wvBrowser.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.i("WEB_VIEW_TEST", "error code:" + errorCode); super.onReceivedError(view, errorCode, description, failingUrl); } }); 

I tested it and it works fine. Check your logs and see what code error you get.

all this can be found at http://developer.android.com/reference/android/webkit/WebView.html

Hope this helps.

+2
source

Just wanted to add another answer. Someone might find my suggestion helpful. You need to add usage permissions to your AndroidManifest.xml. I got a similar error adding this line

 <uses-permission android:name="android.permission.INTERNET" /> 
+6
source

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) { } }); 
+3
source

All Articles