首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分享图像和文件的反应-本机使用世博会

分享图像和文件的反应-本机使用世博会
EN

Stack Overflow用户
提问于 2018-11-22 04:21:08
回答 2查看 7.1K关注 0票数 5

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

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

我试过了

这两种解决方案似乎都不适用于世博会。

我使用的是react原生版本:https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz

代码语言:javascript
复制
FileSystem.downloadAsync(url, FileSystem.documentDirectory+filename).then(({uri})=>{

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

})

我遗漏了什么吗?

EN

回答 2

Stack Overflow用户

发布于 2019-07-14 15:23:36

自SDK33以来,您可以使用世博共享将任何类型的文件共享给其他应用程序,这些应用程序可以处理其文件类型,即使在安卓系统上也是如此。

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

使用非常简单:

代码语言:javascript
复制
import * as Sharing from 'expo-sharing'; // Import the library

Sharing.shareAsync(url) // And share your file !
票数 5
EN

Stack Overflow用户

发布于 2020-07-06 15:18:40

为了让用户共享我们(世博)应用程序中保存的内容,我们这样组织它。(这在iOS和安卓系统中都是可行的)。

  1. 进口共享:
代码语言:javascript
复制
import * as FileSystem from 'expo-file-system';
import * as Sharing from 'expo-sharing';
  1. 在按钮(或任何地方)中添加ONPRESS:
代码语言:javascript
复制
  <Button
   name="share"
   onPress={() =>
      openShareDialogAsync(media, {
         video: media.meta.fileType === 'video',
         })
       }
   />
  1. 将视频或图像共享给用户手机上的任何应用程序
代码语言:javascript
复制
 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);
  };

希望这会有所帮助:]

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53423855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档