Using webView.loadUrl is working for https site , but not with my local page which is located in /Applications/MAMP/htdocs/test.html
webView.loadUrl("/Applications/MAMP/htdocs/test.html") is not working
webView.loadUrl("http://localhost:8080/test.html"); is not working
Below is the test.html file
<!DOCTYPE html>
<html>
<head>
<title>Sample Page</title>
</head>
<body>
<h2>JS alert Example</h2>
<button onclick="myFunction()" >Try it</button>
<script>
function myFunction (){
Android.showToast("Sample Android toast message");
}
</script>
</body>
</html>
Now I want to load this page using webView .
Below is the mainactivity.java code
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
webView = (WebView) findViewById(R.id.webview);
webView.loadUrl("http://127.0.0.1:8080/test.html");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.addJavascriptInterface(new WebAppInterface (this), "Android");
}
}
Below is my WebInterface java class :
public class WebAppInterface {
private Context context;
public WebAppInterface (Context context){
this.context = context;
}
@JavascriptInterface
public void showToast (String message){
Toast.makeText(context,message,Toast.LENGTH_LONG).show();
}
}
Now ,I cant understand why it is not loading the web page mentioned in webView.loadUrl . Note: I having given internet permissions in manifest file.