5

This is my code:

package sai.datla.game; import android.app.Activity; import android.os.Bundle; import android.webkit.WebChromeClient; import android.webkit.WebView; public class GametestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WebView webView = (WebView)findViewById(R.id.webView); webView.getSettings().setJavaScriptEnabled(true); webView.setWebChromeClient(new WebChromeClient()); webView.clearSslPreferences(); webView.loadUrl("file:///android_asset/www/index.html"); } } 

but it is saying that it cannot find the link in the emulator. I have checked many times if my index.html file is in the www folder, which is in my assets, but it won't work. Please help.

By the way I am only twelve years old so please make the answers easy to understand for a child.

1

2 Answers 2

9
// Find view in layout WebView wv = (WebView) findViewById(R.id.webView_tobe_loaded); // Get settings WebSettings wbset = wv.getSettings(); // Enable JavaScript wbset.setJavaScriptEnabled(true); // Set new client (to handle website in your app) wv.setWebViewClient(new MyWebViewClient()); // Example of the URL String url = "http://www.google.com"; // Load website wv.loadUrl(url); 

This code will help you to solve the problem. It worked for me.

Sign up to request clarification or add additional context in comments.

3 Comments

If you get it worked try accepting and upvoting the ans.Its an advantage for both of us to get the reputation points.
Why enable JavaScript twice?
sorry that was a slip...Thanks for notifyning me this.:-).@psyklopz
1

instead of loadUrl, try using the loadDataWithBaseURL method:

webview.loadDataWithBaseURL("android.resource://<package_name>/assets/www/file_name", html, mimeType, encoding, ""); 

1 Comment

Why is loadDataWithBaseUrl better?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.