我正在尝试使用本地file.html从我的应用启动Chrome 这是我的代码:
String url2 = "file:///"
+ Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + "new folder"+ "/index.html";
url2 = url2 .replaceAll(" ", "%20");
Uri uri2 = Uri.parse(url2 );
Intent intent = new Intent(Intent.ACTION_VIEW, uri2);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("com.android.chrome");
try {
startActivity(intent);
} catch (ActivityNotFoundException ex) {
intent.setPackage(null);
startActivity(intent);
}
答案 0 :(得分:4)
试试这个:
Uri uri2 = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + "new folder"+ "/index.html"));
Intent intent = new Intent(Intent.ACTION_VIEW, uri2);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("com.android.chrome", "com.google.android.apps.chrome.Main");
try {
startActivity(intent);
} catch (ActivityNotFoundException ex) {
try {
intent.setPackage(null);
startActivity(intent);
} catch (Exception e) {}
}