【问题标题】:Get data from content provider in React Native从 React Native 中的内容提供者获取数据
【发布时间】:2019-09-12 03:29:24
【问题描述】:

可以建议任何解决方案或代码示例来从 React Native 中的内容提供者 android 获取数据。 目前,我使用“react-native-fs”,但它无法从内容提供者那里获取数据,或者我可能对这个库有误。 我的代码

const uriContent = 'content://xxx.provider/info_all'
const existFile = await RNFS.exists(uriContent)
    if (existFile) {
        const fileContent = await RNFS.readFile(uriContent, 'utf8')
        try {
            const newData = JSON.parse(fileContent)
            // console.log('GOT RESULT UUID', newData.uuid);
            if (newData !== undefined && newData !== null &&
                newData.uuid !== undefined && newData.uuid !== null && newData.uuid.length > 0) {
                return newData.uuid
            } else {
                return ''
            }
        } catch (error) {
            console.log(error.message, error.code)
            return ''
        }
    } else {
        return ''
    }

【问题讨论】:

    标签: react-native


    【解决方案1】:

    你可以使用 RNFS.stat(uriContent) 代替 RNFS.exists(uriContent)。

    State 方法将像这样https://www.npmjs.com/package/react-native-fs#statfilepath-string-promisestatresult 提供文件状态。

    【讨论】:

    • 您可以使用 RNFS.stat(uriContent) 代替 RNFS.exists(uriContent)。 ===> 我用它来检查路径 content:// 是否存在。我关心如何从android中的内容提供者那里获取数据谢谢你的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    • 2012-02-22
    • 2012-07-29
    • 1970-01-01
    相关资源
    最近更新 更多