簡體   English   中英

使用 react native / expo app (android) 打開已安裝的應用程序

[英]Open an installed application using react native / expo app (android)

我自己開發了安裝在我的 android 系統中的apkPlay 商店中沒有)。 我需要在按鈕單擊事件上通過 react-native / expo 應用程序打開該應用程序 是否有可能通過 react-native / expo 應用程序打開該應用程序,而無需互聯網或鏈接到 PlayStore

您應該使用開箱即用的 React Native 中可用的Linking API 這是使用 URI 方案從您的應用程序打開 Whatsapp 的示例,或者您可以使用 Explicit Intent 使用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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM