CB-5592 Set MIME type for openExternal when scheme is file:

This commit is contained in:
Andrew Grieve 2013-12-20 11:17:24 -05:00
parent 98c8b28bf3
commit 59c8e8b46e

View File

@ -630,29 +630,24 @@ public class CordovaWebView extends WebView {
// TODO: What about params? // TODO: What about params?
// Load new URL // Load new URL
this.loadUrl(url); this.loadUrl(url);
return;
} }
// Load in default viewer if not // Load in default viewer if not
else { LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list. Loading into browser instead. (URL=" + url + ")");
LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list. Loading into browser instead. (URL=" + url + ")");
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e);
}
}
} }
try {
// Load in default view intent // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
else { // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
try { Intent intent = new Intent(Intent.ACTION_VIEW);
Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(url);
intent.setData(Uri.parse(url)); if ("file".equals(uri.getScheme())) {
cordova.getActivity().startActivity(intent); intent.setDataAndType(uri, resourceApi.getMimeType(uri));
} catch (android.content.ActivityNotFoundException e) { } else {
LOG.e(TAG, "Error loading url " + url, e); intent.setData(uri);
} }
cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e);
} }
} }