【问题标题】:Web Storage in Cordova app get carried over even if app is removed即使删除了应用程序,Cordova 应用程序中的 Web 存储也会保留
【发布时间】:2018-10-16 23:33:47
【问题描述】:

在 Cordova Android 应用程序中,当我使用 Web 存储 (window.localStorage) 时,我注意到有时当我卸载应用程序(甚至通过 adb uninstall)并再次重建应用程序时,window.localStorage 的东西似乎被携带结束了。

这不仅仅是在一台 Android 设备上,我在不同的设备上多次注意到它。

这是可能的还是只是页面被缓存了?

编辑:

我创建了一个示例项目。并使用 Cordova 8 和 Android 平台 7.0.0。配置对了吗?

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloWorld</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
            <application android:allowBackup="false" />
            <application android:fullBackupContent="false" />
        </edit-config>
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <engine name="android" spec="^7.0.0" />
</widget>

【问题讨论】:

    标签: android cordova local-storage


    【解决方案1】:

    Android 6+ 会自动备份数据,并在您再次安装应用时恢复。

    您可以通过将其添加到 config.xml 来禁用它

    <edit-config file="AndroidManifest.xml"
                 target="/manifest/application"
                 mode="merge">
        <application android:allowBackup="false"/>
        <application android:fullBackupContent="false"/>
    </edit-config>
    

    这会导致应用构建失败,您必须将xmlns:android="http://schemas.android.com/apk/res/android" 添加到 config.xml 小部件才能使其构建。

    【讨论】:

    • 这适用于 Cordova 7.1.0 吗?它给我一个未绑定的前缀错误。
    • 是的,我刚刚尝试了一个使用 Cordova CLI 7.1.0 创建的新应用程序,它运行良好。你得到什么错误?
    • @huggie 未绑定的前缀可能是由社交分享插件引起的,请尝试降级到以前的版本
    • 我创建了一个新的 hello world 项目,它仍然有同样的错误。安卓平台6.3.0。我把它放在&lt;platform name="android"&gt;&lt;/platform&gt; 里面,然后我试着把它放在外面。它仍然对我不起作用。
    • 啊,我只是检查了 AndroidManifest.xml 是否正在被编辑,但没有尝试运行应用程序,那就是你的错误出现的时候。要修复它,请将您的 config.xml 从 &lt;widget id="com.example.hello" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"&gt; 更改为 &lt;widget id="com.example.hello" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0"&gt;
    猜你喜欢
    • 2016-12-11
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 2011-02-10
    • 2015-08-09
    相关资源
    最近更新 更多