问题
My webview is able to load both https & http sites But not https://www.google.com
It doesn't throw any error either.
Here is my code.I am unable to solve this problem
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button btn = (Button) findViewById(R.id.Button1);
final EditText et=(EditText)findViewById(R.id.EditText1);
final WebView wv1=(WebView)findViewById(R.id.WebView1);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.getSettings().setDomStorageEnabled(true);
wv1.setInitialScale(100);
et.setFocusable(true);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
wv1.loadUrl(et.getText().toString());
}
});
wv1.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
ca
public void onPageFinished(WebView view, String url) {
Toast.makeText(getApplicationContext(),"Page Finished",Toast.LENGTH_LONG).show();
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
}
});
wv1.loadUrl("https://www.bing.com");
Thanks for any kind of help.
回答1:
There is a bug in your code
Your code
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
Correct code
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
ShouldOverrideUrlLoading
should return false
to open url in webview.
True
is for opening in some other app.
来源:https://stackoverflow.com/questions/28484286/webview-is-not-opening-google-com