skip to Main Content

I am trying to open google from using react-native Linking.openUrl in my app.
what happens is, it opens the browser but right after opening the browser it closes the browser and my app.

my code

    const url = "https://www.google.com";
    try {
      const canOpen = await Linking.canOpenURL(url);
      console.log(canOpen); // it returns true
      if (canOpen) {
        Linking.openURL(url);
      }
    } catch (error) {
      console.log("the error is ", error);
    }

I tried with other urls as well and the same happens. Can open is true, It opens a browser but right after opening the browser, it closes the browser and my app.

I did search online but could not find any potential solution.

2

Answers


  1. Chosen as BEST ANSWER

    After testing different cases and solutions. I found out that, there was an issue with the emulator I was using. When I used it with an actual device It was working fine.

    Thanks for your comments and answer


  2. Kindly try this and see if there is any error occured:

    import { Linking } from 'react-native';
    
    const url = "https://www.google.com";
    
    Linking.openURL(url)
    .catch(err => console.error('Error opening URL:', err));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search