作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
String url = "<html><body>hello World</body></html>";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
如何在浏览器中加载 HTML 源代码?请举例说明。
最佳答案
Intent i = new Intent();
// MUST instantiate android browser, otherwise it won't work
i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
i.setAction(Intent.ACTION_VIEW);
String html = "<html><body>hello World</body></html>";
// May work without url encoding, but I think is advisable
// URLEncoder.encode replace space with "+", must replace again with %20
String dataUri = "data:text/html," + URLEncoder.encode(html).replaceAll("\\+","%20");
i.setData(Uri.parse(dataUri));
startActivity(i);
关于android - 在 ANDROID 浏览器中加载 HTML 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9644974/
我是一名优秀的程序员,十分优秀!