我有一个由静态本地文件组成的网站,我正在尝试将其加载到 Intent 中。它使用 JavaScript,所以我的印象是我必须使用 Intent 而不是 WebView。
该文件位于“assets/site_files/index.html”。 这是我尝试使用的代码:
Uri path = Uri.parse("file:///android_asset/site_files/index.html");
Intent intent = new Intent(Intent.ACTION_VIEW, path);
startActivity(intent);
应用程序在启动 Intent 时崩溃,这是控制台中的最后一个条目:
ActivityManager: Starting: Intent
如果我在网络服务器上加载网站而不是尝试加载本地版本,则应用程序可以正常工作。以下效果完美:
Uri path = Uri.parse("http://www.domain.com/test_app_static/index.html");
Intent intent = new Intent(Intent.ACTION_VIEW, path);
startActivity(intent);
但是,我需要它在本地运行,以便用户可以在没有互联网连接的情况下运行它。 我环顾四周并尝试了几种不同的解决方案,但在将本地 html 文件加载到 Intent 的特定情况下,它们都不适合我。请帮忙!
最佳答案
正确的网址是file:///android_asset/site_files/index.html
。应用程序崩溃的原因是 asset
文件只能由您的应用程序访问。因此,您需要在 WebView
中显示该数据。
关于android - 在 Android 中将本地 html 文件加载到 Intent 的正确路径是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13190299/