Android浏览器如何打开本地html文件

2024-11-16 18:02:01
推荐回答(1个)
回答1:

代码 如下:

Intent intent=new Intent();
intent.setAction("android .intent.action.VIEW");
Uri CONTENT_URI_BROWSERS = Uri.parse("content://com.android.htmlfileprovider/sdcard/123.html");
intent.setData(CONTENT_URI_BROWSERS);
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
startActivity(intent);
假设要打开的本地html文件 存放在如下路径 /sdcard/123.html

如果出现错误:

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



intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));

代替

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