我已经使用FileSystem.downloadAsync保存了我想要在本地共享的文件
Share.share适用于iOS。如何共享我在Android上本地保存的图像?
我试过了
这两种解决方案似乎都不适用于世博会。
我使用的是react原生版本: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});
}
})我遗漏了什么吗?
发布于 2019-07-14 15:23:36
自SDK33以来,您可以使用世博共享将任何类型的文件共享给其他应用程序,这些应用程序可以处理其文件类型,即使在安卓系统上也是如此。
请参阅:https://docs.expo.io/versions/latest/sdk/sharing/
使用非常简单:
import * as Sharing from 'expo-sharing'; // Import the library
Sharing.shareAsync(url) // And share your file !发布于 2020-07-06 15:18:40
为了让用户共享我们(世博)应用程序中保存的内容,我们这样组织它。(这在iOS和安卓系统中都是可行的)。
import * as FileSystem from 'expo-file-system';
import * as Sharing from 'expo-sharing'; <Button
name="share"
onPress={() =>
openShareDialogAsync(media, {
video: media.meta.fileType === 'video',
})
}
/> const openShareDialogAsync = async (mediaProp, options) => {
const fileDetails = {
extension: options.video ? '.mp4' : '.jpg',
shareOptions: {
mimeType: options.video ? 'video/mp4' : 'image/jpeg',
dialosTitle: options.video
? 'Check out this video!'
: 'Check out this image!',
UTI: options.video ? 'video/mp4' : 'image/jpeg',
},
};
const downloadPath = `${FileSystem.cacheDirectory}${mediaProp.media_id}${fileDetails.extension}`;
const { uri: localUrl } = await FileSystem.downloadAsync(
mediaProp.url,
downloadPath
);
if (!(await Sharing.isAvailableAsync())) {
showMessage({
message: 'Sharing is not available',
description: 'Your device does not allow sharing',
type: 'danger',
});
return;
}
await Sharing.shareAsync(localUrl, fileDetails.shareOptions);
};希望这会有所帮助:]
https://stackoverflow.com/questions/53423855
复制相似问题