Akashsingla19
Akashsingla19

Reputation: 690

How to open Other app from ReactNative?

How to open other apps (Gmail, Camera) from ReactNative. How can I pass data from current scene to other app?

Upvotes: 7

Views: 14904

Answers (4)

Anton L.
Anton L.

Reputation: 818

react-native-app-link has some redundant config (e.g. appStoreLocale parameter), so I wrote my own realization using their code:

import { Alert, Platform, ToastAndroid } from 'react-native';

const isIos = Platform.OS === 'ios';

const showNotification = (text) => isIos
  ? Alert.alert(text)
  : ToastAndroid.show(text, ToastAndroid.SHORT);

const openApp = ({ url, appStoreId, playMarketId, name }) => {
  Linking.openURL(url).catch(err => {
    if (err.code === 'EUNSPECIFIED') {
      Linking.openURL(
        isIos
          ? `https://apps.apple.com/app/id${appStoreId}`
          : `https://play.google.com/store/apps/details?id=${playMarketId}`,
      );
    } else {
      showNotification(`Can't open ${name} app`);
    }
  });
};

It tries to open the app by the specified link, and if the user doesn't have such one, it opens its page in AppStore or Play Market.

Upvotes: 0

SkyTreasure
SkyTreasure

Reputation: 884

I found this npm library react-native-app-link which can open other apps. This is based on deep linking, if you have any deep links then this library can help. This doesn't open apps just by giving the android package name or ios app id.

https://github.com/FiberJW/react-native-app-link

Upvotes: 1

saumya
saumya

Reputation: 63

Code sample for opening the dialer

const urlToOpen = 'tel:1234567890';
Linking.openURL(urlToOpen);

You can refer to the official doc here, it just predefines some applications, which can be opened.

However, if the question is about to open just about any application, I hope there is no solution till now.

Upvotes: 0

Ahmed Ali
Ahmed Ali

Reputation: 2668

you can mange opening other apps using Linking

Upvotes: 0

Related Questions