New changes added for the system browser open

The code supported Android API levels of more than 13 also the Google Pixel 7 pro for the capacitor user. also Cordova .
This commit is contained in:
CHARAN BHIMSING TATU 2023-05-03 18:54:03 +05:30 committed by GitHub
parent 8ee1d38821
commit f81500840a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -454,20 +454,46 @@ public class InAppBrowser extends CordovaPlugin {
*/ */
public String openExternal(String url) { public String openExternal(String url) {
try { 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 intent = null;
intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(url);//"googlechrome://navigate?url="+ url
// Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".   intent = "data".equals(scheme)
// Adding the MIME type to http: URLs causes them to not be handled by the downloader.                     ? Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Build.VERSION.SDK_INT >= 33 ? Intent.CATEGORY_BROWSABLE : Intent.CATEGORY_APP_BROWSER)
Uri uri = Uri.parse(url);                     : new Intent(Intent.ACTION_VIEW);
if ("file".equals(uri.getScheme())) {     if ("file".equals(scheme)) {
intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));                 intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
} else {                 LOG.d(LOG_TAG,"if loop on java_______________*******");
intent.setData(uri);             } else {
}                 intent.setData(uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());                 LOG.d(LOG_TAG,"else loop on java_________________*****");
// CB-10795: Avoid circular loops by preventing it from opening in the current app             }
this.openExternalExcludeCurrentApp(intent);             LOG.d(LOG_TAG,"before putExtra");
return "";             //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 // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
} catch (java.lang.RuntimeException e) { } catch (java.lang.RuntimeException e) {
LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString()); LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());