Skip to content

Repository files navigation

Local Host Library

A local server library to load web projects into android web view.

How To Use?

  • add jitpack to your project

    // in project's root build.gradle
    allprojects {
    repositories {
    // ...
    maven { url 'https://jitpack.io' }
    }
    }
    // or in settings.gradle file
    dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
    google()
    mavenCentral()
    maven { url "https://jitpack.io" }
    }
    }
  • Then import the library. tag:

    dependencies {
    implementation 'com.github.fcat97:local-server:Tag'
    }

Now to use,

  1. Start the server & Set the web project's root path (where the index.html file is):

    ServerProvider.startServer()
    ServerProvider.setDistDir(distHelper.getDistPath(distName))
  2. Now just load the local host root i.e. http://127.0.0.1:9099 in WebView.

    if (ServerProvider.currentState isServerState.Running) {
    val url = (ServerProvider.currentState asServerState.Running).url
    webView.loadUrl(url)
    }
  3. Remember to enable javascript and domStorage

    webView.apply {
    @SuppressLint("SetJavaScriptEnabled")
    settings.javaScriptEnabled =true
    settings.domStorageEnabled =trueif (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) {
    webViewClient =this@DistViewActivity.webViewClient
    }
    }

    All done.


Happy coding 🚀

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages