如何在Android上正确检测用户操作?

问题描述 投票:0回答:1

我正在 Expo React Native 应用程序上使用来自 react-native-share

Share.open

在 Android 上,无论用户是否共享或取消,

Share.open()
始终返回
{ success: false, dismissedAction: true }
。所以,我无法正确检测用户操作。

在 Android 设备和模拟器上测试,结果相同。

我需要添加一些配置才能使其工作吗? 是否有解决方法或修复程序可以正确检测 Android 上的用户操作?

这是我打开共享表的代码。

import Share from "react-native-share";

const onShare = async () => {
  try {
    const res = await Share.open({
      title: "Invite Friends",
      message: `Hi there, Hello! Please install this app:\n`,
      url: playStoreLink,
      failOnCancel: false,
    });

    console.log(res);

    if (res.success) {
      showAlert("Shared successfully", "success");
    } else if (res.dismissedAction) {
      showAlert("Dismissed sharing", "success");
    }
  } catch (err) {
    showAlert("Failed to share", "error");
  }
};

套餐。

{
    "expo": "~51.0.22",
    "react-native": "0.74.3",
    "react-native-share": "^11.0.3"
}
react-native expo react-native-share
1个回答
0
投票

无法通过共享库知道哪个应用程序用户单击了对话框,因为平台不提供回调。解决方法是通过桥接获取可共享的应用程序并显示您的自定义对话框。

© www.soinside.com 2019 - 2024. All rights reserved.