I use a WebView
in my app. When the app is not connected to the internet I want to serve the site locally. I was able to build the APK
and install the app onto my device, but when I start the app offline, it is just showing the body PHP
, but it did not call/load the CSS
File or include the PHP
files.
Directory structure in Android Studio :
This is my MainActivity
:
public class Callback extends WebViewClient{
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Toast.makeText(getApplicationContext(), "No Internet Access!", Toast.LENGTH_SHORT).show();
view.loadUrl("file:///android_asset/nointernet.php");
}
}
This is my "No Internet" page
<body>
<!-- Navigation Bar -->
<?php include 'assets\inc\navmobpage.php'; ?>
<!-- Page Content -->
<div class="container" align="center" style="background-color: white;padding-top: 50px;">
<img src="assets\img\nointernet.png" width="100%" />
<a class="btref" href="http://xx.xx.xx">REFRESH</a>
</div>
<?php include 'assets\inc\footmob.php'; ?>
<!-- Bootstrap core JavaScript -->
<script src="assets\general\jquery\jquery.min.js"></script>
<script src="assets\general\bootstrap\js\bootstrap.bundle.min.js"></script>
</body>