Code example for WebView: Displaying web pages

Methods: addJavascriptInterfacegetSettingsloadUrlsetScrollBarStylesetWebChromeClientsetWebViewClient

0
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         
        web = new WebView(this);
        web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        setContentView(web);
         
        web.getSettings().setJavaScriptEnabled(true);
        web.getSettings().setAllowFileAccess(true);
        WebViewJavascriptInterface javascriptInterface = new WebViewJavascriptInterface();
        web.addJavascriptInterface(javascriptInterface, "android");
        web.setWebChromeClient(new WebChromeClient());
        web.setWebViewClient(new GenericWebViewClient());
         
        Intent intent = getIntent();
        String contentProviderBaseUri = intent.getStringExtra("base_uri");
        try { 
            server = new HttpServer(6789, "/explorer");
            server.registerHandler("/db", new DatabaseHandler(new AndroidContentResolver(getContentResolver()), contentProviderBaseUri));
        } 
        catch (IOException e) {
            Toast.makeText(this, "Cannot create builtin data browser. Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
            finish();
            return; 
        } 
         
        String url = "http://" + javascriptInterface.getMyIpAddress() + ":6789/index.html";
        if(intent.getData() != null) {
            url = intent.getData().toString();
        } 
        Toast.makeText(this, "Loading \n" + url, Toast.LENGTH_LONG).show();
        web.loadUrl(url);
    } 
     
    @Override 
    protected void onDestroy() { 
        if(server != null) {
Connect your IDE to all the code out there  Get Codota for Java