Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
x-and authored Feb 20, 2021
1 parent caf8dee commit 114569d
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions framework/src/org/apache/cordova/CordovaWebViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,31 +229,26 @@ public void showWebPage(String url, boolean openExternal, boolean clearHistory,
return;
}

Intent intent;

if (url.startsWith("intent://")) {
try {
Intent intent = null;
try {
if (url.startsWith("intent://")) {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException e) {
e.printStackTrace();
return;
}

} else {
intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(url);
// Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
// Adding the MIME type to http: URLs causes them to not be handled by the downloader.
if ("file".equals(uri.getScheme())) {
intent.setDataAndType(uri, resourceApi.getMimeType(uri));
} else {
intent.setData(uri);
intent = new Intent(Intent.ACTION_VIEW);
// To send an intent without CATEGORY_BROWSER, a custom plugin should be used.
intent.addCategory(Intent.CATEGORY_BROWSABLE);
Uri uri = Uri.parse(url);
// Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
// Adding the MIME type to http: URLs causes them to not be handled by the downloader.
if ("file".equals(uri.getScheme())) {
intent.setDataAndType(uri, resourceApi.getMimeType(uri));
} else {
intent.setData(uri);
}
}
// To send an intent without CATEGORY_BROWSER, a custom plugin should be used.
intent.addCategory(Intent.CATEGORY_BROWSABLE);
}
try {
cordova.getActivity().startActivity(intent);
} catch (URISyntaxException e) {
LOG.e(TAG, "Error parsing url " + url, e);
} catch (ActivityNotFoundException e) {
if (url.startsWith("intent://") && intent != null && intent.getStringExtra("browser_fallback_url") != null) {
showWebPage(intent.getStringExtra("browser_fallback_url"), openExternal, clearHistory, params);
Expand Down

0 comments on commit 114569d

Please sign in to comment.