The problem with webview does not load

I have a bad experience with webview that does not load the webpage I am requesting.

I cannot load Google or any other webview page. I added xml:

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_marginLeft="250px"
         android:layout_marginTop="80px"
    android:layout_width="180px"
    android:layout_height="160dip"
/>

Then I insert the code:

mWebView = (WebView) findViewById(R.id.webview);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.loadUrl("http://www.google.com");

This indicates that the webpage is not available.

I also added manifest permission.

I have another action in this application that loads youtube url with:

startActivity(new Intent( Intent.ACTION_VIEW,
                                Uri.parse("http://www.youtube.com/watch?v=XS998HaGk9M")));// Starts an intent to watch the video

I am not sure if this may be and really needs advice on this, as I need to get it to work.

thank

Edit: I also cannot access any webpage in the emulator itself. When you search in the search bar in the emulator, it says the same thing when connected to Google.

I'm not sure why this will be related to youtube with intent, not web browsing

: youtube, , . , , . - , . , , , .

: , , , youtube , . webview. : (

+5
4

, " "

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

. , - , MainActivity.onCreate(). , , webview.loadUrl(…) onClick . WebView .

+2

Does the emulator have internet access? I sometimes observed similar behavior in the emulator, and due to improper start of the emulator. The only working round I could think of was to restart the emulator until it got access to the Internet (usually once or twice).

Dan

+1
source
 package com.Example.Browser;

 import android.app.Activity;
 import android.os.Bundle;
 import android.view.KeyEvent;
 import android.view.View;
 import android.webkit.WebSettings;
 import android.webkit.WebSettings.PluginState;
 import android.webkit.CookieManager;
 import android.webkit.WebView;
 import android.webkit.WebSettings.RenderPriority;
 import android.webkit.WebViewClient;

 public class MainActivity extends Activity {


private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    CookieManager.getInstance().setAcceptCookie(true);//Enable Cookies

    mWebView = (WebView) findViewById(R.id.webView1);
    mWebView.getSettings().setJavaScriptEnabled(true);//Enable Java Script
    mWebView.setWebViewClient(new HelloWebViewClient());
    mWebView.loadUrl("http://www.google.com/"); //Set Home page
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);//Remove ScrollBars
    mWebView.getSettings().setDefaultFontSize(12);//Set Font Size
    mWebView.getSettings().setLoadsImagesAutomatically(true);//Enable Image Loading
    mWebView.getSettings().setPluginState(PluginState.ON);//Enable Flash
    mWebView.getSettings().setRenderPriority(RenderPriority.HIGH); //improves Feedback     on touch
    //mWebView.setBackgroundColor(0x00000000);//Transparent Screen When Loading
    //mWebView.getSettings().setBuiltInZoomControls(true);//Set Zoom Controls 
    //mWebView.getSettings().setDisplayZoomControls(false);//Always Hide Zoom     Controlls(Requires Api 11)

    mWebView.getSettings().setAppCacheMaxSize(1024*1024*8);//Set Cache (8mb)
    String appCachePath =     getApplicationContext().getCacheDir().getAbsolutePath();//Set Cache (8mb)
    mWebView.getSettings().setAppCachePath(appCachePath);//Set Cache (8mb)
    mWebView.getSettings().setAllowFileAccess(true);//Set Cache (8mb)
    mWebView.getSettings().setAppCacheEnabled(true);//Set Cache (8mb)
    mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);//Set Cache (8mb)

    mWebView.requestFocus(View.FOCUS_DOWN);//Enable WebView Interaction

    //mWebView.setWebViewClient(new WebViewClient() {//Open URL on Error
    //public void onReceivedError(WebView view, int errorCode, String description,     String failingUrl) {//Open URL on Error   
    //mWebView.loadUrl("http://www.google.com");//Open URL on Error 

    //mWebView.loadUrl("file:///android_asset/error_404.jpg"); //Show Offline HTML     file or Image on Error 
    //  }
    // });
  }

private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{


webview.loadUrl(url);
return true;
}
}

 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event)
 {

 if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())

{
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}


<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"
tools:context=".MainActivity" >

 <WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>
+1
source

All Articles