Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with webview not loading

I am having a bad experience with webview which does not load the web page which I request.

I cannot load google or any other page with a webview. I have put in 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"
/>

I then put in the code:

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

This shows up stating the webpage is not available.

I have also added the permission to the manifest.

I have another activity within this application which loads a youtube url fine using:

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

I'm not sure what this could be and really need advice on this as I need to get it working.

Thanks

Edit: I also cannot access any webpage within the actual emulator itself. By searching in the search bar within the emulator this says the same thing when connecting to Google.

I'm not sure why this would connect to youtube with an intent and not a webview

Edit: This is not even connecting to youtube now, it says the same as above. This is messed up as I need this to work for my project tomorrow. If the webview keeps going down this is not very reliable. I may have to change the device I'm working with as with android things keep going wrong.

Edit: I have just come back after a few hours without touching the code or the emulator and when I run the application the youtube video was back on and I can browse within the emulator. But I still cannot connect via webview. VERY UNRELIABLE :(

like image 676
Raj Avatar asked Mar 06 '11 13:03

Raj


People also ask

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.

How can I improve my WebView performance?

I read about how to increase performance of WebView by implementing Caching web resources like JS, CSS and image files. You can also static resources in your native application, and by intercepting the Resource requests you can override the default behaviour of WebView.

What browser is used in WebView?

On Android 7.0, 8.0 and 9.0, Google Chrome handles the embedded browsing functions. On other Android OS versions, web app performance may suffer without WebView enabled.

How do I open WebView in browser?

Android Webview open link in browser code snippet. myWebWiev = (WebView)findViewById(R. id. myWebWiev); myWebWiev.


1 Answers

Make sure you have included Permissions for Internet Access

<uses-permission android:name="android.permission.INTERNET" />
like image 119
Brighton Vino Avatar answered Oct 25 '22 07:10

Brighton Vino