代码之家  ›  专栏  ›  技术社区  ›  GOXR3PLUS

使用expo共享从“expo assets”共享图像会产生神秘错误

  •  0
  • GOXR3PLUS  · 技术社区  · 3 年前

    我在开发客户端上使用最新的expo-47,我负责创建自定义的开发客户端,其中包括我在给定代码上使用的库。


    因此,我将解释我的情况(我的目标是android):

    1. 在当地的世博会资产中,我有30张图片

    enter image description here

    我想允许用户 共有 使用的图像 expo-sharing 但我犯了错误[见文章末尾]

    enter image description here

    以下是我尝试过的许多代码的示例,但都不起作用:

    import * as Sharing from 'expo-sharing'
    
    async function shareImage(imageURI) {
        try {
            await Sharing.shareAsync(require('../../../assets/images/motivational/36.jpg'))
        } catch (error) {
            console.log(error)
        }
    }
    

    错误如下:

    [Error: Argument of an incompatible class: class java.lang.Double cannot be passed as an argument to parameter expecting class java.lang.String.]
    

    这是什么意思?

    enter image description here

    我当然已经验证了图像存在于给定的路径上

    1 回复  |  直到 3 年前
        1
  •  0
  •   pr0to    3 年前

    移除 require 来自的语句 .shareAsync

    这样写:
    await Sharing.shareAsync('../../../assets/images/motivational/36.jpg')
    -或者-
    先定义路径,然后将其称为 await Sharing.shareAsync(imageURI)

    如果这能解决问题,请告诉我。

    推荐文章