capacitor-plugins
capacitor-plugins copied to clipboard
bug: appUrlOpen listener not called on Android if app launched with ACTION_MAIN
Bug Report
Plugin(s)
Core App plugin on Android, Capacitor 2.4.3
Capacitor Version
Latest Dependencies:
@capacitor/cli: 2.4.4
@capacitor/core: 2.4.4
@capacitor/android: 2.4.4
@capacitor/electron: 2.4.4
@capacitor/ios: 2.4.4
Installed Dependencies:
@capacitor/ios not installed
@capacitor/cli 2.4.3
@capacitor/core 2.4.3
@capacitor/android 2.4.3
@capacitor/electron not installed
Platform(s)
Android
Current Behavior
When the app is launched with a uri and ACTION_MAIN, the appUrlOpen listener is NOT called. If the app is launched the same way but with ACTION_VIEW then the appUrlOpen listener IS called.
Expected Behavior
The appUrlOpen listener should be called as long as there is some data uri ... even if the action is ACTION_MAIN. The code currently checks both the uri and action and only continues if the action is set to ACTION_VIEW.
I'm not sure exactly what should be checked here ... but ideally, this listener should also be called if the app is launched with ACTION_MAIN.
With the Cordova com.lampa.startapp plugin, by default, when you launch another application, the intent will have ACTION_MAIN. When using the Cordova Custom-URL-scheme plugin in the launched app, this would call the app's handleOpenURL method. I would like to convert the launched app to Capacitor and use the Capacitor App plugin instead of the Cordova Custom-URL-scheme plugin. However, this doesn't work ... because the Capacitor plugin does not call the appUrlOpen listener when the app is launched with ACTION_MAIN. Unfortunately, it is not practical to change all of the apps that launch this app to always launch with ACTION_MAIN.
Code Reproduction
Other Technical Details
Additional Context
A simple fix for this would be to remove the check for ACTION_VIEW in the handleOnNewIntent method in App.java (or at least add a check for ACTION_MAIN as well as ACTION_VIEW
A workaround for this issue is to use the plugin cordova-plugin-customurlscheme in your capacitor app. See also: https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/332
I'm experiencing this problem using Capacitor v2 latest, any planned fix?