標籤:android c style class blog code
網上好多說法 但實際上說到點上的沒有 不想寫太長 直接進入正題
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
【完】