简体   繁体   English

Android模拟器中的Webview问题

[英]Webview Problem in android emulator

I am having difficulty in opening a webview within my application. 我在应用程序中无法打开Webview。

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. 我不确定为什么无法打开Web视图,我需要此功能,因为我在应用程序中有视图。

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. 我没有在logcat中收到任何错误,只是说网页不可用。

Thanks 谢谢

Have you put internet permission into your AndroidManifest.xml file? 您是否已将Internet权限放入AndroidManifest.xml文件?

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. 有时,由于Internet共享问题,WebView无法在操作系统上运行的模拟器上运行。 You can try it by running on external android device. 您可以通过在外部android设备上运行来尝试。

Sample Simple WebView Activity 示例简单的WebView活动

Java Class Activity File - Code Snippet Java类活动文件-代码段

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布局文件

<?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 并确保您已向AndroidManifest.xml添加权限

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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