我可以从java层访问存储在React Native的AsyncStorage中的数据吗? [英] Can I access data stored in React Native's AsyncStorage from java layer?
问题描述
我使用 AsyncStorage
在React Native中存储了一些用户首选项。现在,我需要从后台服务中获取这些偏好。我无法从Java层访问 AsyncStorage
。有办法吗?
I am storing few user preferences in React Native using AsyncStorage
. Now, I need to get those preference from a background service. I can't access AsyncStorage
from the Java layer. Is there a way to do it?
在iOS中,我们可以导入 RCTAsyncLocalStorage.h
并调用 _getValueForKey
。但是,我找不到在Android中这样做的方法。
In iOS, We can import RCTAsyncLocalStorage.h
and call _getValueForKey
. But, I can't find a way to do it in Android.
推荐答案
我试图使用 AsyncStorage
。但是,我做不到。所以,我构建了一个React Native插件来从javascript层访问Android的Native SharedPreferences
。我已经在github上发布了它( https://github.com/sriraman/react-native -shared-preferences )
I tried to use the AsyncStorage
from the java layer. But, I couldn't. So, I built a React Native plugin to access Android's Native SharedPreferences
from the javascript layer. I have published it in the github (https://github.com/sriraman/react-native-shared-preferences)
现在我从<$ c $使用这个 SharedPreferences
c> Java 和 React Native
图层。
Now I'm using this SharedPreferences
from both Java
and React Native
layer.
这篇关于我可以从java层访问存储在React Native的AsyncStorage中的数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!