首页 > 解决方案 > WhatsApp 使用 Android 中的 expo 共享库共享(React-native)

问题描述

我想将图像文件直接共享到我的whatsApp 或将其添加到我的whatsApp 状态,即当我单击按钮共享任何图像时,我不想看到任何其他共享选项。目前我正在使用以下代码分享

import * as Sharing from 'expo-sharing';
import * as FileSystem from 'expo-file-system';

const customShare = async (image) => {
    const base64result = image.split(',')[1];
    try {
        let filename = 'share.png'; // or some other way to generate filename
        let filepath = `${FileSystem.documentDirectory}/${filename}`;
        await FileSystem.writeAsStringAsync(filepath, base64result, { encoding: 'base64' });
        await Sharing.shareAsync(filepath, { mimeType: 'image/gif' })
    } catch (e) {
        alert(e.message);
    }
};


但是这里显示所有共享选项可供选择,有没有办法跳过这一步直接打开我的WhatsApp

标签: javascriptreactjsreact-nativeexpo

解决方案


推荐阅读