Skip to content

Payment OR Data link open in system browser for the supported android 13 new changes Added. #1001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,20 +454,46 @@ private HashMap<String, String> parseFeature(String optString) {
*/
public String openExternal(String url) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try {
                Uri uri = Uri.parse(url);
                String scheme = uri.getScheme();
                Intent intent = null;
                intent = "data".equals(scheme)
                    ? Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)
                    : new Intent(Intent.ACTION_VIEW);
               
                if ("file".equals(scheme)) {
                    intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
                } else {
                    intent.setData(uri);
                }
               
               // intent.setPackage("com.android.chrome"); // Specify the package name of Chrome
               
                PackageManager packageManager = cordova.getActivity().getPackageManager();
                List resolveInfoList = packageManager.queryIntentActivities(intent, 0);
               
                if (resolveInfoList.size() > 0) {
                    cordova.getActivity().startActivity(Intent.createChooser(intent, "com.android.chrome"));
                } else {
                    // Chrome is not installed,
                    intent.setPackage(null);
                    cordova.getActivity().startActivity(Intent.createChooser(intent, "com.android.chrome"));
                }
               
                return "";
            } catch (Exception e) {
                LOG.d(LOG_TAG, "InAppBrowser: Error loading url " + url + ": " + e.toString());
                return e.toString();
            }

try {
Intent intent = null;
intent = new Intent(Intent.ACTION_VIEW);
// 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.
Uri uri = Uri.parse(url);
if ("file".equals(uri.getScheme())) {
intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
} else {
intent.setData(uri);
}
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
// CB-10795: Avoid circular loops by preventing it from opening in the current app
this.openExternalExcludeCurrentApp(intent);
return "";
// Intent intent = null;
// intent = new Intent(Intent.ACTION_VIEW);
// // 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.
// Uri uri = Uri.parse(url);
// if ("file".equals(uri.getScheme())) {
// intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
// } else {
// intent.setData(uri);
// }
// intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
// // CB-10795: Avoid circular loops by preventing it from opening in the current app
// this.openExternalExcludeCurrentApp(intent);
// return "";
Intent intent = null;
Uri uri = Uri.parse(url);//"googlechrome://navigate?url="+ url
  intent = "data".equals(scheme)
                    ? Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Build.VERSION.SDK_INT >= 33 ? Intent.CATEGORY_BROWSABLE : Intent.CATEGORY_APP_BROWSER)
                    : new Intent(Intent.ACTION_VIEW);
    if ("file".equals(scheme)) {
                intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
                LOG.d(LOG_TAG,"if loop on java_______________*******");
            } else {
                intent.setData(uri);
                LOG.d(LOG_TAG,"else loop on java_________________*****");
            }
            LOG.d(LOG_TAG,"before putExtra");
            //intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
            LOG.d(LOG_TAG,"after putExtra__________________"+intent+"+++"+cordova.getActivity().getPackageName());
            // CB-10795: Avoid circular loops by preventing it from opening in the current app
             if (intent.resolveActivity( cordova.getActivity().getPackageManager()) == null) {
                 LOG.d(LOG_TAG," Not null loop code aadded java_________________*****"+intent);
                        // intent.setPackage("com.android.chrome");
                      //intent.setSelector(emptyBrowserIntent);
                      cordova.getActivity().startActivity(intent);
              }
           // this.openExternalExcludeCurrentApp(intent);
            //intent.setPackage("com.android.chrome");
            this.cordova.getActivity().startActivity(intent);
            return "";
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
} catch (java.lang.RuntimeException e) {
LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
Expand Down