网上好多说法 但实际上说到点上的没有 不想写太长 直接进入正题

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.fromFile(htmlPath), "text/html");
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
} else {
    startActivity(Intent.createChooser(intent, ""));  // 这个有时候不起作用 不知道为什么……
}

不加

intent.addCategory(Intent.CATEGORY_BROWSABLE);

因为可能会有ActivityNotFoundException

不加

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

因为可能没有default browser。

如果html path是在一个private的路径下, 就需要用自己写一个content provider来用content://com.android.htmlfileprovider/+file absolution path来访问。具体实现参照 http://blog.csdn.net/wen0006/article/details/6224979

【完】

posted on 2014-05-30 15:47  我是猴面包的树  阅读(2975)  评论(0编辑  收藏  举报