我在我的应用程序中使用了 WebView
。当应用程序未连接到互联网时,我想在本地为网站提供服务。我能够构建 APK
并将该应用程序安装到我的设备上,但是当我离线启动该应用程序时,它只显示正文 PHP
,但它没有调用/加载 CSS
文件或包含 PHP
文件。
Android Studio 中的目录结构:
这是我的 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");
}
}
这是我的“无互联网”页面
<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>
最佳答案
Android 不附带 PHP
服务器。因此,对于所有常见的 Intent 和目的,不可能在本地提供 .php
文件。
您需要重写您的离线页面才能在没有任何 PHP
代码的情况下运行。
我假设您引用的 CSS
也是 PHP
包含的一部分,因此由于同样的原因没有加载。
关于javascript - 为什么我的 CSS 和 PHP 包含没有加载到我的 WebView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57753726/