2012-03-16 16 views
7

पर उपयोगकर्ता डेटा साफ़ करें या साफ़ कैश साफ़ करें फ़ोनमैप और एंड्रॉइड का उपयोग करके मैं उपयोगकर्ता डेटा या साफ़ कैश कैसे साफ़ कर सकता हूं? नीचे दिया गया कोड काम नहीं करता है। मुझे परिवर्तन कहां करना चाहिए; एचटीएमएल तरफ या जावा पक्ष पर? इसके अलावा मैं एक AJAX अनुरोध तक पहुंच रहा हूं और PUT विधि के दूसरे प्रयास पर, डेटा अपडेट नहीं होता है, इसलिए मेरा प्राथमिक संदिग्ध उपयोगकर्ता डेटा है जो एंड्रॉइड स्टोर करता है। मैंने अपने AJAX अनुरोध पर cache: false जोड़ा है यह सुनिश्चित करने के लिए कि यह कैश को स्टोर नहीं करता है। लेकिन यह अभी भी काम नहीं करता है। कोई राय कि इसे कैसे ठीक किया जाए?फ़ोनगैप एंड्रॉइड

मेरे पास यह कोड किसी अन्य प्रश्न से आधारित है।

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(); 
} 

तो मूल रूप से मेरी 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(); 
} 
} 
+0

मैं AJAX डाल अनुरोध को डीबग करना शुरू कर दूंगा, क्योंकि कैश के साथ: झूठी, आपको कभी भी दो बार एक ही प्रतिक्रिया नहीं मिलनी चाहिए - jQuery स्वचालित रूप से ऐसे अनुरोध के लिए टाइमस्टैंप जोड़ता है, इसे कैश किए जाने से रोकता है –

+0

... भी, मेरे पास है एंड्रॉइड डिवाइस पर आंतरिक कैश को साफ़ करने के लिए सफलतापूर्वक इस्तेमाल किए गए कोड का उपयोग किया गया, इसलिए मुझे लगता है कि कोड ठीक काम करता है –

उत्तर

3

कोड नीचे अपना OnCreate में लोड हो रहा है index.html के बाद() गतिविधि फ़ाइल की विधि जोड़ें:

if (super.appView != null) { 
    super.appView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 
} 
1

मैं अपने कॉर्डोबा आवेदन में कैश को साफ़ करने के लिए एक आसान तरीका के लिए देख रहा था, और पाया this plugin जो निम्नलिखित कोड का उपयोग कर एंड्रॉयड में WebView कैश को साफ करता है:

// clear the cache 
self.webView.clearCache(true); 

और आईओएस में, पृष्ठभूमि में चलता है और ऐसा करते हैं:

[[NSURLCache sharedURLCache] removeAllCachedResponses]; 

प्लगइन का उपयोग करने के लिए बस मेरे लिए सौभाग्य से window.CacheClear(success, error);

कहते हैं, यह समस्या मैं था हल किया। इस cordova-plugin-cache-clear के लेखक के लिए बड़ा धन्यवाद!

संबंधित मुद्दे