加载HTML code在Android浏览器 [英] Load HTML code in ANDROID BROWSER

查看:111
本文介绍了加载HTML code在Android浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 字符串URL =< HTML><身体GT;的Hello World< / BODY>< / HTML>中;
    意图I =新的意图(Intent.ACTION_VIEW);
    i.setData(Uri.parse(URL));
    startActivity(ⅰ);
 

我怎么可以加载HTML源代码code在浏览器?敬请个例子来说吧。

解决方案

 意向书我=新意图();

//必须实例化Android浏览器,否则将无法正常工作
i.setComponent(新单元名(com.android.browser,com.android.browser.BrowserActivity));
i.setAction(Intent.ACTION_VIEW);

字符串的HTML =< HTML><身体GT;的Hello World< /身体GT;< / HTML>中;

//可能工作没有UR​​L编码,但我认为是可取
// URLEn coder.en code用+代替空格,必须再次替换为%20
字符串dataUri =数据:text / html的,+ URLEn coder.en code(HTML).replaceAll(\\ +,%20);
i.setData(Uri.parse(dataUri));

startActivity(ⅰ);
 

String url = "<html><body>hello World</body></html>";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);

how can i load the HTML source code in the browser? Please kindly explain with an example.

解决方案

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);

这篇关于加载HTML code在Android浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆