首页 > 解决方案 > 使用 Expo 在 react-native 上共享图像和文件

问题描述

我已经保存了要在本地共享的文件FileSystem.downloadAsync

Share.share 适用于 iOS。如何分享我在 Android 上本地保存的图像?

我试过了

这两种解决方案似乎都不适用于 Expo

我正在使用 react-native 版本:https ://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz

FileSystem.downloadAsync(url, FileSystem.documentDirectory+filename).then(({uri})=>{

    if(Platform.OS == "android"){
        // ???
    }
    else{
        Share.share({url:uri});
    }

})

有什么我想念的吗?

标签: androidreact-nativeexpo

解决方案


从 SDK33 开始,您可以使用 Expo Sharing 将任何类型的文件共享给其他可以处理其文件类型的应用程序,即使您在 Android 上也是如此。

请参阅:https ://docs.expo.io/versions/latest/sdk/sharing/

用法很简单:

import * as Sharing from 'expo-sharing'; // Import the library

Sharing.shareAsync(url) // And share your file !

推荐阅读