简体   繁体   中英

Eclipse: APP can't access the internet

My main class look like this:

public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.internetview);

  String url = "https://www.google.de";
  WebView view =(WebView) this.findViewById(R.id.webView1);

  view.getSettings().setJavaScriptEnabled(true);
  view.loadUrl(url);
}

and my internetview.xml like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_margin="0dp" />
</RelativeLayout>

If i have the line

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

in my Manifest the WebView is permanently white... and without this line the WebView show the Error cant find or acces the internet.

The crazy thing is that the Emulator browser work normaly.

The following has worked for me, where I start a new activity and have this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView mWebView=new WebView(YOUR_CLASS_NAME.this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.getSettings().setAllowFileAccess(true);
    mWebView.loadUrl(url);
    setContentView(mWebView);
}

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