让我们试着用这段代码。我们将查询可以打开这个MIME类型的活动并找到完全的htmlviewer应用程序。试试你的自我。我不测试,所以不确定它是否正常工作,但它是主要想法。
MimeTypeMap mime = MimeTypeMap.getSingleton();
String mimetype = mime.getMimeTypeFromExtension("html");
Intent htmlIntent = new Intent(Intent.ACTION_VIEW);
htmlIntent.setDataAndType(Uri.fromFile(htmlFile), mimetype);
PackageManager packageManager = getPackageManager();
List canViewActivity = packageManager.queryIntentActivities(htmlIntent, 0);
for (ResolveInfo resolve : canViewActivity) {
if ((resolve.activityInfo.name).contains("html_viewer_package")) {
final ActivityInfo htmlActivity = resolve.activityInfo;
final ComponentName componentName = new ComponentName(htmlActivity.applicationInfo.packageName, htmlActivity.name);
htmlIntent.addCategory(Intent.CATEGORY_LAUNCHER);
htmlIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
htmlIntent.setComponent(componentName);
startActivity(htmlIntent);
break;
}
}