【问题标题】:Open an installed application using react native / expo app (android)使用 react native / expo app (android) 打开已安装的应用程序
【发布时间】:2022-01-01 14:46:22
【问题描述】:

我有自己开发的 apkPlay 商店中没有安装在我的 Android 系统中。而且我需要通过按钮点击事件上的 react-native / expo 应用程序打开该应用程序。是否有可能通过 react-native / expo 应用打开该应用无需互联网或链接到 PlayStore

【问题讨论】:

    标签: android react-native expo


    【解决方案1】:

    您应该使用开箱即用的 React Native 中可用的 Linking API。这是一个使用 URI 方案从您的应用打开 Whatsapp 的示例,或者您可以使用显式意图使用 Linking.sendIntent 打开其他应用。

    import React, { useCallback } from "react";
    import { Alert, Button, Linking, StyleSheet, View } from "react-native";
    
    const OpenWhatsappButton = ({ action, children }) => {
    const handlePress = useCallback(async () => {
    try {
      await Linking.openURL(action);
      } catch (e) {
      Alert.alert(e.message);
     }
    }, [action]);
    
    return <Button title={children} onPress={handlePress} />;
    
    };
    
    const App = () => {
    return (
    <View style={styles.container}>
      <OpenWhatsappButton action="whatsapp://send?text=">
        Whatsapp
      </OpenWhatsappButton>
    </View>
    );
    };
    
     const styles = StyleSheet.create({
    container: { flex: 1, justifyContent: "center", alignItems: "center" },
    });
    
    export default App;
    

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 2017-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      相关资源
      最近更新 更多