Skip to content
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

tel: links throw exception #6483

Closed
jonathan-k4 opened this issue Apr 10, 2023 · 7 comments · Fixed by #6489
Closed

tel: links throw exception #6483

jonathan-k4 opened this issue Apr 10, 2023 · 7 comments · Fixed by #6489
Labels
platform: android type: bug A confirmed bug report

Comments

@jonathan-k4
Copy link

!(url.getHost().equals(appUri.getHost()) && url.getScheme().equals(appUri.getScheme())) &&

When opening a tel: link, an exception is thrown. url.getHost() can return null if no host is found, and .equals() is being called without a check for null.

@ionitron-bot ionitron-bot bot added the triage label Apr 10, 2023
@media4learning
Copy link

To add to this - for me, any link like window.location = crashes the app on android.

@veneliniliev
Copy link

veneliniliev commented Apr 11, 2023

the same thing happens to me!

Fatal Exception: java.lang.NullPointerException Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference

@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Apr 11, 2023
@ionitron-bot ionitron-bot bot removed the triage label Apr 11, 2023
@Ionitron
Copy link
Collaborator

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 💙

@Ionitron Ionitron added the needs reply needs reply from the user label Apr 11, 2023
@media4learning
Copy link

media4learning commented Apr 11, 2023

Repoduction is here:

https://github.com/media4learning/broken-links.git

npm i
npm run build
npx cap add android
npx cap sync
npx cap open android
run on a device
Tap the "crash app(Android only) button
App crashes

The problem is using window.location = "X" with X being any mailto, tel, posssibly any link

Android Studio run output displays:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.ionic.starter, PID: 25353
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.getcapacitor.Bridge.launchIntent(Bridge.java:374)
at com.getcapacitor.BridgeWebViewClient.shouldOverrideUrlLoading(BridgeWebViewClient.java:28)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(chromium-TrichromeWebViewGoogle.aab-stable-556311630:89)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loopOnce(Looper.java:186)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

@Ionitron Ionitron removed the needs reply needs reply from the user label Apr 11, 2023
@jonathan-k4
Copy link
Author

jonathan-k4 commented Apr 11, 2023

Simple patch fix until it’s fixed permanently…

diff --git a/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/Bridge.java
index 9013422..de2717d 100644
--- a/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/Bridge.java
+++ b/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/Bridge.java
@@ -371,7 +371,7 @@ public class Bridge {
 
         Uri appUri = Uri.parse(appUrl);
         if (
-            !(url.getHost().equals(appUri.getHost()) && url.getScheme().equals(appUri.getScheme())) &&
+            !((url.getHost() != null && url.getHost().equals(appUri.getHost())) && url.getScheme().equals(appUri.getScheme())) &&
             !appAllowNavigationMask.matches(url.getHost())
         ) {
             try {

@jcesarmobile jcesarmobile added platform: android type: bug A confirmed bug report and removed needs reproduction needs reproducible example to illustrate the issue labels Apr 11, 2023
@Vadiara50
Copy link

Simple patch fix until it’s fixed permanently…

diff --git a/node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/Bridge.java

     Uri appUri = Uri.parse(appUrl);
     if (
  •        !(url.getHost().equals(appUri.getHost()) && url.getScheme().equals(appUri.getScheme())) &&
    
  •        !((url.getHost() != null && url.getHost().equals(appUri.getHost())) && url.getScheme().equals(appUri.getScheme())) &&
           !appAllowNavigationMask.matches(url.getHost())
       ) {
           try {
    

Thanks a lot. It helped!

@ionitron-bot
Copy link

ionitron-bot bot commented May 14, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android type: bug A confirmed bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants