首页 > 编程知识 正文

android界面如何显示html中的内容,html怎么用在android上

时间:2023-05-03 14:24:02 阅读:206905 作者:2615

我试图在设备浏览器中加载本地html文件。我尝试过使用WebView,但它不适用于所有设备。如何在Android浏览器中加载本地HTML文件

//WebView method that didnt work for all devices

WebView w = new WebView(this);

w.getSettings().setJavaScriptEnabled(true);

w.loadUrl("file:///android_asset/my.html");

setContentView(w);

所以我尝试这种方法,这将打开一个HTML浏览器的文件,但不能正常工作,因为我试图加载HTML需要JavaScript

// html view that also doesnt work

Intent i = new Intent();

//i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this is optional

i.setAction(Intent.ACTION_VIEW);

i.setDataAndType(Uri.fromFile(myFile), "text/*");

startActivity(i);

香港专业教育学院环顾四周,在每天至少尝试这样做的不同的方式,比如增加

i.addCategory(Intent.CATEGORY_BROWSABLE);

i.setClassName("com.android.browser", "com.android.browser.BrowserActivity");

但他们返回错误,如

Unable to start activity android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] typ=text/html }

Unable to start activity android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.browser/com.android.browser.BrowserActivity}; have you declared this activity in your AndroidManifest.xml?

为我做到这一点的最好的办法就是直接从资产文件夹,这是我所知道的是使用的WebView这么简单加载HTML,但就像我说这不工作像设备Galaxy Nexus和Nexus 7,它可以在像kindle fire和kindle hd这样的设备上工作。

,但目前使用的方法IM是将其从资产文件夹到外部存储器保存,并从那里获取文件通过的意图,这犯规是因为JavaScript的问题的工作负载。有什么建议么?谢谢

+0

您的webView是否启用了JavaScript? –

+0

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。