android - 使用 Expo 在 react-native 上共享图像和文件
问题描述
我已经保存了要在本地共享的文件FileSystem.downloadAsync
Share.share 适用于 iOS。如何分享我在 Android 上本地保存的图像?
我试过了
- https://github.com/lucasferreira/react-native-send-intent
- https://github.com/react-native-community/react-native-share
这两种解决方案似乎都不适用于 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});
}
})
有什么我想念的吗?
解决方案
从 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 !
推荐阅读
- reactjs - 如何在第一次渲染时处理空值?
- sqlite - 如何“重新编译”具有更高附加限制的 Sqlite
- java - (JAVA)有没有更有效的方法来做到这一点?
- php - 为什么这个 && 不会触发为假?
- amazon-web-services - 配置 ec2 以运行脚本以从 sftp 站点下载文件?
- python - 如何正确设置此 while 循环?
- python - Python 中的 Kolmogorov-Smirnov 拟合优度检验
- r - 启用 observeEvent 来触发 eventReactive 事件
- vue.js - 在子路径级别的 Traefik 中设置 2 个 Vue.js 应用程序时出错
- r - R中的数据框拆分或重构