react-native - 从 React Native 中的内容提供者获取数据
问题描述
可以建议任何解决方案或代码示例以从 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 ''
}
解决方案
您可以使用 RNFS.stat(uriContent) 代替 RNFS.exists(uriContent)。
State 方法将像这样https://www.npmjs.com/package/react-native-fs#statfilepath-string-promisestatresult提供文件状态
推荐阅读
- python-3.x - Discord bot.py 文件无法加载扩展 [discord.py 重写]
- dart - 如何在颤动中返回异步函数的值?
- c++ - 如何将音频字节转换为样本
- c# - 无效的 URI:无法解析权威/主机 Appium
- javascript - 为“脚本”使用单独的文件
- c# - 如何在 MVC 中使用视图模型
- c++ - 包装递归可变参数模板类会改变行为。为什么?
- java - 如何解开列表
- amazon-web-services - 如何在 AWS 管理控制台中查看 DynamoDB 查询结果计数
- python - findall 返回整个正则表达式匹配作为其第一个索引,即使其中存在一个组