Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android webview error Page not found

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");      
    }   
}
like image 656
HLto Dm Avatar asked Jan 19 '13 03:01

HLto Dm


2 Answers

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" />
like image 166
Praishgm Avatar answered Oct 09 '22 04:10

Praishgm


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) {

       }
     });
like image 3
Janmejoy Avatar answered Oct 09 '22 04:10

Janmejoy