CB-5592 Android - Add MIME type to Intent when opening file:/// URLs To avoid the "No Activity found to handle Intent..." error.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/176890f3 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/176890f3 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/176890f3 Branch: refs/heads/master Commit: 176890f30599fc72d33eeb1f5daa1fa5e6358325 Parents: 2bd006b Author: gianluca <[email protected]> Authored: Thu Oct 3 14:11:12 2013 +0200 Committer: Andrew Grieve <[email protected]> Committed: Fri Dec 20 11:06:10 2013 -0500 ---------------------------------------------------------------------- src/android/InAppBrowser.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/176890f3/src/android/InAppBrowser.java ---------------------------------------------------------------------- diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index da6b241..aa89446 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -300,7 +300,12 @@ public class InAppBrowser extends CordovaPlugin { try { Intent intent = null; intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); + Uri uri = Uri.parse(url); + if ("file".equals(uri.getScheme())) { + intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri)); + } else { + intent.setData(uri); + } this.cordova.getActivity().startActivity(intent); return ""; } catch (android.content.ActivityNotFoundException e) {
