Convert my localhost website into android app-ThrowExceptions

Exception or error:

I want to create a web view of a localhost website or not online website how can I do that its picking online websites link but not localhost is there a way to do this?

I have tried giving the link using localhost and ip but it’s not picking my website.

MainActivity.java


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
 private WebView mywebview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mywebview = findViewById(R.id.webview);
        WebSettings webSettings = mywebview.getSettings();
        webSettings.getJavaScriptEnabled();
        mywebview.loadUrl("http://192.000.00.0/traveland/index.php");
        mywebview.setWebViewClient(new WebViewClient());
    }

    @Override
    public void onBackPressed()
    {
        if(mywebview.canGoBack())
        {
            mywebview.goBack();
        }
        else
        {
            super.onBackPressed();
        }

    }
}

MainActivity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp"
        android:id="@+id/webview"/>
</RelativeLayout>```

It shows all the online websites not the offline ones how can that be done?
How to solve:

Your pc and android must be in the same network, once you have turned on your web server (WAMP, XAMPP, Etc.) configure the vitualhots, with the firewall disabled from your pc.

###

If your localhost is working well and you want to make it an app that connects with the server localhost through your android then download the “ngrok” on your PC. there are tons of tutorials that will teach you how to host localhost websites online once you do that you are going to paste that ngrok URL which is online version of your website and then name your app give your email and just submit like a normal form and you will be receiving email and there will be two links. one for public link sharing of your app and another is private app management which will allow you to change some functions of your app like URL
and others just change the URL to your localhost URL and then you will be able to access your contents of localwebsite without ngrok keep in mind if you change layout of your web application then you must update your app through same process again
link for making app with this website: https://gonative.io/

Leave a Reply

Your email address will not be published. Required fields are marked *