I am trying to find a way how to open the google play store with my application when the user is pressing a button inside of the react-native application. Is there a way how to do this?
If people are too lazy to read through the annoyingly SPA dev docs of android:
market://details?id=<package_name>
In react-native land:
Linking.openURL("market://details?id=<package_name>");
Example:
Linking.openURL("market://details?id=googoo.android.btgps");
Edit: Make sure to import Linking
in order to use it
import { View, Text, StyleSheet, Linking } from 'react-native';
You can use deeplinking to redirect your user from your app using this: https://developer.android.com/distribute/tools/promote/linking.html
and the Linking
API from react-native: http://facebook.github.io/react-native/docs/linking.html
For future users, you could go on to read the docs from the accepted answer for more info. But if you want a faster result, here it is.
Using Linking
from react-native
as
import { Linking } from 'react-native'
Linking.openURL("http://play.google.com/store/apps/details?id=<package_name>")
If you're using expo, then the below code is for you.
Install the expo-linking
package via expo install expo-linking
import * as Linking from "expo-linking";
Linking.openURL("http://play.google.com/store/apps/details?id=<package_name>")
NOTE: <package_name>
is your app's package name defined in the manifest file or app.json
if you're using expo
Seems like this package is a cool alternative.
Available for React Native, and Expo
This worked for me: Go to google play. search your app there and copy the url and put like below
import { Linking } from "react-native";
Linking.openURL("your app url her")
Expo Linking docs mentions.
It's possible that the user doesn't have the Lyft app installed, in which case you may want to open the App / Play Store, or let them know that they need to install it first. We recommend using the library react-native-app-link for these cases.
It's got an MIT license so we're good to use it.
Let's see how that library does it!
https://github.com/FiberJW/react-native-app-link/blob/master/index.js
export const openInStore = async ({ appName, appStoreId, appStoreLocale = 'us', playStoreId }) => {
if (Platform.OS === 'ios') {
Linking.openURL(`https://apps.apple.com/${appStoreLocale}/app/${appName}/id${appStoreId}`);
} else {
Linking.openURL(
`https://play.google.com/store/apps/details?id=${playStoreId}`
);
}
};
So I modified it to:
export const openInStore = async (config: {
appStoreConfig: {
appName: string;
appId: string;
storeLocale: string;
};
playStoreConfig: {
appId: string;
};
}) => {
if (Platform.OS === "ios") {
await Linking.openURL(
`https://apps.apple.com/${config.appStoreConfig.storeLocale}/app/${config.appStoreConfig.appName}/id${config.appStoreConfig.appId}`
);
} else if (Platform.OS === "android") {
await Linking.openURL(
`https://play.google.com/store/apps/details?id=${config.playStoreConfig.appId}`
);
}
};
Usage:
try {
openInStore({
playStoreConfig: {appId: "com.stevemoretz.test"},
appStoreConfig: {
appId: "com.stevemoretz.test",
appName: "Test",
storeLocale: "us",
},
});
} catch (e) {}
Should work but haven't been tested yet!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.