React Native 如何使用Linking.canOpenUrl在Android上打开WhatsApp

h43kikqp  于 2023-10-22  发布在  React
关注(0)|答案(1)|浏览(207)

我想在react native上使用buttton press打开whatsapp。但是我想使用Linking.canOpenUrl?我该怎么做呢?
我尝试在react native中向androidManifest.xml文件添加Intent,

<queries>
   <intent>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="whatsapp" />
</intent>
</queries>
42fyovps

42fyovps1#

将Intent添加到androidManifest.xml文件

<queries>Share.Social.WHATSAPP
      <!-- Specific apps you share to -->
      <package android:name="com.whatsapp" />
      <intent>
        <action android:name="android.intent.action.SEND" />
      </intent>
    </queries>

分享文件或文本到WHATSAPP的示例
npm i react-native-share

import Share from 'react-native-share';

 let options = {
        title: "APP",
        message: "",
        url: "Url is here",
        subject: "",
        social: Share.Social.WHATSAPP,
        forceDialog: true,
    }
    Share.shareSingle(options)
        .then((response) => {
             // handle response here
        }).catch((error) => {
            // handle error here
        })

相关问题