2

I am writing code to launch other applications from my react native application for android and ios.

Using Linking form react native I am able to redirect to Play Store/App Store but

How can I launch App if it's already installed?

* I am getting the list of the app's from server

enter image description here

Linking.openURL('https://play.google.com/store/apps/details?id=com.example.myapp&hl=en')

Is there any way that I can launch the app if it's installed else redirect to App store/play store with respect to the platform?

Reference:react-native-app-link

Sagar
  • 5,273
  • 4
  • 37
  • 50
  • I don't understand what you want! You want to open other apps it's already installed in your app ? – DevAS Nov 14 '19 at 12:45
  • It depends upon which app you wants to open and what data you have to pass in that app.Suppose you want to open map app from your RN app .with custom latitude&longitude values.For that you can use this one var scheme = Platform.OS === 'ios' ? 'maps:' : 'geo:'; var url = scheme + `${lat},${lng}`; Linking.openURL(url); Import {Linking} from "react-native" – Abdul Basit Mangat Nov 14 '19 at 12:59
  • @AbdulBasit I just want to launch the app, I have app with name `Sagar` and package name `com.sagar` so how can I go for same – Sagar Nov 14 '19 at 13:14
  • `Linking.canOpenURL(yourApp ).then(supported => { if (supported) { Linking.openURL(yourApp); } else { alert("sorry invalid url"); }` – DevAS Nov 14 '19 at 13:57

2 Answers2

4

After many searches I have found an alternative for android without deep link URL is to use the native module react-native-intent-launcher to launch another app using package-name.

You can call the native function startActivity in react-native to do something with Intent which can only be solved with android native code.

Looking for iOS solution without deep link URL if any lead please update here

Once I found I will update Here

Thank you

Sagar
  • 5,273
  • 4
  • 37
  • 50
1

Your other app need to handle Deeplinking. If that's not already the case, have a look here for Android and here for iOS.

This will allow you to have your app's own URL scheme, for example testapp://example

Then you can simply use the Linking API, but instead of opening a HTTP URL, you can use you Deeplink URL scheme defined previously.

Linking.openURL('testapp://example');
Neeko
  • 1,139
  • 1
  • 10
  • 26
  • 1
    can we access the random app if only having `app name and package name` using react-native – Sagar Nov 15 '19 at 04:16
  • @Sagar, sadly you can't. It has to be a URL as you can see here: https://facebook.github.io/react-native/docs/linking.html#openurl the only way to get a URL for your app is through deep linking. – Neeko Nov 15 '19 at 07:52
  • is there any way to achieve with react native – Sagar Nov 15 '19 at 07:53
  • Without updating the "target" app no. The only other alternative is to open the Store as you did. – Neeko Nov 15 '19 at 08:16