I have created one android project with simple web view.
I am trying to open google. But the emulator screen is saying Google not available.
I have added Internet permission in the manifest file. Even I am able to access google from Emulator browser. Only in the application, I am not able access. Nothing is printed in the log also.
Please help.
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http:/开发者_开发知识库/schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
mWebView.setWebViewClient(new HelloWebViewClient());
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
<uses-permission android:name="android.permission.INTERNET" />
Your code above does not show the manifest file that gives rights to use internet. This process is detailed here: Building Web Apps in WebView
If you have further trouble you can test and download source code of this open source base application for Android: WebViewApp
remove or comment out this line
mWebView.setWebViewClient(new HelloWebViewClient());
Since you have override
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
and returned yes, it might have meant that you have handled url loading. You basically don't need the webviewclient subclass here
精彩评论