Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - WebView = Web page not available

Tags:

When using a WebView view in my app, no matter what page I force it to visit, it says Web page not found. Here is my code:

MainActivity.java

package com.testing.webview;  import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView;  public class MainActivity extends Activity {     @Override     public void onCreate( Bundle savedInstanceState )     {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);          WebView webView = (WebView) findViewById(R.id.webView1);         WebSettings webSettings = webView.getSettings();         webSettings.setBuiltInZoomControls(true);         webView.loadUrl("http://www.google.com");             } } 

main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical">     <WebView         android:id="@+id/webView1"         android:layout_width="fill_parent"         android:layout_height="fill_parent" />                 </LinearLayout> 

It's very basic code as you can see. There is indeed an internet connection as I can open the normal Browser app and visit any webpage like normal.

like image 981
Jake Wilson Avatar asked Sep 14 '11 21:09

Jake Wilson


People also ask

Why are some Web pages not available on Android?

Hopefully the cause for this “webpage not available” issue on your cell phone was simply a problem with your internet browsers homepage. In which case manually entering your desired URL or changing your phones default homepage will once again allow you to browse and surf the web once again.

What can I use instead of WebView?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.

What permission does WebView require to work?

Android Permissionsxml file is necessary for an Activity to load a web page into a WebView.


1 Answers

Are you using the correct Internet permission?

<uses-permission android:name="android.permission.INTERNET"></uses-permission> 
like image 170
tier1 Avatar answered Oct 01 '22 15:10

tier1