简体   繁体   中英

Webview Problem in android emulator

I am having difficulty in opening a webview within my application.

I can open it within other applications but not the one I want.

Also I can only open up webpages using

startActivity(new Intent(
    Intent.ACTION_VIEW,
    Uri.parse("http://www.google.com")));

I am not sure why I cannot open webviews, I need this to work as I have a view within my application.

The way I am opening the webview is

setContentView(R.layout.webview);
WebView wv = (WebView)findViewById( R.id.link4_view );          
wv.loadUrl("http://www.google.com");

I do not receive any error in logcat, just says web page not available.

Thanks

Have you put internet permission into your AndroidManifest.xml file?

It should look like:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" .... >
...
    <uses-permission android:name="android.permission.INTERNET" />
...
</manifest>

The only way I could get this to work properly was by taking out the permission then loading the application. Then closing it and re-adding the permission and it worked :)

Sometimes WebView is not working on emulator running on operating system due to internet sharing problem. You can try it by running on external android device.

Sample Simple WebView Activity

Java Class Activity File - Code Snippet

setContentView(R.layout.main);
WebView MyWebView = (WebView) findViewById(R.id.webkit);        
MyWebView.getSettings().setJavaScriptEnabled(true);
MyWebView.loadUrl("http://www.stackoverflow.com");

XML Layout File

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <WebView android:id="@+id/webkit" android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:scrollbars="none" />
</ScrollView>

And Make Sure You Have Added Permission To Your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM