WebView error. Building an Android app to view my site

So, I have a website with a mobile version. I am trying to make an application for it.

This is my activity_main.xml file

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

      

and this is my MainActivity.java class

package com.example.esouqbh.esouq;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.example.esouqbh.esouq.R;

public class MainActivity extends Activity
{@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar as we already have it in the web app
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Point to the content view defined in XML
setContentView(R.layout.activity_main);
//Configure the webview setup in the xml layout
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
//Yes, we want javascript, pls.
webSettings.setJavaScriptEnabled(true);
//Make sure links in the webview is handled by the webview and not sent to a full browser
myWebView.setWebViewClient(new WebViewClient());
//And let the fun begin
myWebView.loadUrl("http://esouqbh.com");    }}

      

for some reason when i run the app it says on my phone (i run the APP on my phone as an emulator) i get this error

Web-page is unavailable

The web page http://esouqbh.com cannot be loaded as:

Net :: ERR_CACHE_MISS

Please note that my site works fine with no problem if I open it from my browser or phone.

EDIT :: found a solution by adding

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

      

in androidmanifest.xml!

+3


source to share


1 answer


NO, this is not a folder, adding:

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

      



in you AndroidManifest.xml

means that your application will load the page from the internet into yourWebView

Internet Allow : Allows applications to open network sockets.

+5


source







All Articles