open chrome with local file in android -
hello trying launch chrome app local file.html here code:
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); }
i open manually paste url in chrome works fine. when opening application opens text file html code not in chrome in text viewer
try this:
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) {} }
Comments
Post a Comment