在Phonegap android上清除用户数据或清除缓存

jon*_*aag 7 ajax android caching cordova

如何使用PhoneGap和Android清除用户数据或清除缓存?下面的代码不起作用.我应该在哪里进行更改; 在HTML方面还是在Java方面?此外,我正在访问一个AJAX请求,并且在PUT方法的第二次尝试中,数据不会更新,因此我的主要疑问是Android存储的用户数据.我添加cache: false了我的AJAX请求以确保它不存储缓存.但它仍然无效.有想法该怎么解决这个吗?

我有这个代码来自另一个问题.

public static void deleteCache(Context context) {
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
        }
    } catch (Exception e) {}
}

public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }
    return dir.delete();
}
Run Code Online (Sandbox Code Playgroud)

所以基本上我的POSActivity.java看起来像这样.

public class PocActivity extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    super.setIntegerProperty("splashscreen", R.drawable.is);
    super.setIntegerProperty("loadUrlTimeoutValue", 60000);
    deleteCache(this);
    super.loadUrl("file:///android_asset/www/index.html");
}

public static void deleteCache(Context context) {
    try {
        File dir = context.getCacheDir();
        if (dir != null && dir.isDirectory()) {
            deleteDir(dir);
        }
    } catch (Exception e) {}
}

public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
    }
    return dir.delete();
}
}
Run Code Online (Sandbox Code Playgroud)

小智 3

加载index.html后,在活动文件的oncreate()方法中添加以下代码:

if (super.appView != null) {
     super.appView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
}
Run Code Online (Sandbox Code Playgroud)