我已经构建了一个 Cordova 应用程序 (cordova -v 7.0.1,cordova-android 6.1.0)。
这包括自动启动。这意味着当定义时,在应用程序中,蓝牙设备已连接,应用程序将启动。
实现方式:
- 保存蓝牙地址到localStorage(file__0.localstorage).//JS端
- BroadcastReceiver,在 bluetooth.device.action.ACL_CONNECTED 上。如果连接的设备与我们的 LocalStorage Start 应用程序中的设备匹配,则检索 localStorage (file__0.localstorage)。// native 端
这是在 2016 年底编译的。它一直有效到现在,即使是更新的、软件方面的设备。
我决定进行一些应用更新,但现在它停止工作了。经过一些调试后,我发现无法读取 file__0.localstorage。这是我目前所拥有的:
File dataDir = new File(context.getFilesDir().getParent());
File appWebViewFilesDir = new File(dataDir, "app_webview/Local Storage/file__0.localstorage");
Log.d(TAG, "Absolute path is " + appWebViewFilesDir.getAbsolutePath());
//Result (rooted phone): path is given.
//Result (UNrooted phone): path is given.
Log.d(TAG, "Fine name is " + appWebViewFilesDir.getName());
//Result (rooted phone): name is given.
//Result (UNrooted phone): name is given.
Log.d(TAG, "Is file Readable " + appWebViewFilesDir.canRead());
//Result (rooted phone): true.
//Result (UNrooted phone): false.
Log.d(TAG, "Tring to set file to readable? " +appWebViewFilesDir.setReadable(true));
//Result (rooted phone): true.
//Result (UNrooted phone): false.
Log.d(TAG, "Tring to set file to readable for all users? " + appWebViewFilesDir.setReadable(true, true));
//Result (rooted phone): true.
//Result (UNrooted phone): false.
Log.d(TAG, "Is file Readable " + appWebViewFilesDir.canRead());
//Result (rooted phone): true.
//Result (UNrooted phone): false.
Log.d(TAG, "Does this file exist " + appWebViewFilesDir.exists());
//Result (rooted phone): true.
//Result (UNrooted phone): false.
任何想法什么时候改变的?
有什么想法可以使 localStorage file__0.localstorage 无需 root 设备即可访问吗?
是否可以在不实现新的数据存储系统的情况下解决这个问题?
附言在这种情况下,数据持久性并不那么重要。
最佳答案
这并不是真正的 Android 7 问题。 localstorage 似乎依赖于 webview。并且webview可以独立升级。
Is possible to solve this without having to implement a new data storage system?
是的。 file__1.localstorage 是一个 SQLLite 数据库。现在,在同一个文件夹 app_webview/Local Storage
中,您应该找到另一个文件夹 leveldb
。 LevelDB是谷歌创建的数据库。您可以使用 java 包装器,leveldb-android例如,访问它。然后您应该使用迭代器遍历条目,寻找您需要的条目。在我的例子中,调用 get()
返回了 null
。
关于javascript - Cordova WebView 的 localStorage 在 Android 7 中无法访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46729436/