1

I'm about to give up, because I've spent hours and hours on this issue, I even found people with the exact same problem, running almost the exact same code, and no answers for them.

I have a webpage that I do not own, but I copy it's page source into my HTML file in the assets folder.

The webview loads the page and whatever data is displayed at the time. Problem #1: the page is dynamic, it changes every few seconds.

Problem#2: The page is displayed just like in the 2 links below. Images are missing, the page looks really barebones.. I don't know why.

WebView not showing website correctly and WebView not showing correctly

Problem#3: SOME pages that load, look fine and I can visit their links, BUT they stay static, and the page is very dynamic (think reddit).

my code is

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //get reference to webview
        WebView webView = (WebView)findViewById(R.id.myWebview);

        //enable javascript on browser
        webView.getSettings().setJavaScriptEnabled(true);


        webView.setWebViewClient(new WebViewClient(){   
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                view.loadUrl(url);
                return false;
            }
        });


        String myUrl = "file:///android_asset/newfile.html";
        webView.loadUrl(myUrl);



    }

When I try using webView.loadDataWithBaseUrl();

the webview only displays a white page with just the path to my html file

for example

file:///android_asset/newfile.html

and thats it.

I am out of ideas, I hope someone can help.

EDIT: Grammar and syntax.

Community
  • 1
  • 1
Dean Z
  • 57
  • 1
  • 9

1 Answers1

0

First of all, clear this:

  1. You are accessing a dynamic site (Defination: Site with database access, CMS etc.)
  2. Are you having trouble showing images on your page uploaded

when you are loading an HTML file in assets folder, you need to know that you also have to upload images, CSS and every related content along with it.

Second:

Below code i wrong

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url){
            view.loadUrl(url);
            return false;
        }
    });


    String myUrl = "file:///android_asset/newfile.html";
    webView.loadUrl(myUrl);

it should be:

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url){
            webView.loadUrl(url); // --------> POINTED FAULT
            return false;
        }
    });


    String myUrl = "file:///android_asset/newfile.html";
    webView.loadUrl(myUrl);

Check the case in weView.loadUrl (...), is it WebView or webView

Try it and confirm...

  • changing the override method `shouldOverrideUrlLoading()` asks me to change my webview to `final`. Overriding it by just using the methods parameter `view` works just fine. But, I went ahead and did it anyway. It produced no change. You did say when you are loading an HTML file in assets folder, you need to know that you also have to upload images, CSS and every related content along with it, I'm going to go look at how to do that. – Dean Z Jan 26 '14 at 06:52