android - 如何检查设备上是否安装了 WhatsApp?

标签 android ios react-native whatsapp

Linking.openURL(`whatsapp://send?phone=${phoneNumber}`);

上面的代码将导航到 WhatsApp,但是我想知道是否可以在尝试 openURL

之前检查 WhatsApp 是否存在

最佳答案

来自 React Native documentation :

To start the corresponding activity for a link (web URL, email, contact etc.), call

Linking.openURL(url).catch(err => console.error('An error occurred', err));

If you want to check if any installed app can handle a given URL beforehand you can call

Linking.canOpenURL(url).then(supported => {
  if (!supported) {
    console.log('Can\'t handle url: ' + url);
  } else {
    return Linking.openURL(url);
  }
}).catch(err => console.error('An error occurred', err));

我假设,如果未安装 WhatsApp,将调用 !supported block ,您可以在那里进行计算。

关于android - 如何检查设备上是否安装了 WhatsApp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52440796/

相关文章:

ios - 如何消除两个连续 CAKeyframeAnimation 动画之间的奇怪延迟?

ios - 如果我的 iOS 设备获得 MFI 许可证,我是否可以将其与自定义蓝牙设备配对?

ios - 如何重新定位 MKMapView 的指南针?

ios - 错误 : typedef redefinition with different types ('NSInteger' (aka 'long' ) vs 'enum ACAccountCredentialRenewResult' )

android - react native 分析。 Systrace 未显示 JS 和 native 模块线程

android - 如何在 android/ios 中使用 cordova ionic 2 打印期间添加打印机

打开另一个应用程序时 Android 应用程序关闭 [未崩溃]