From 8577055d5ac128f57d0fd7d49fb7aa0a700bb715 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 14 May 2015 10:40:25 +0800 Subject: [PATCH] Implement localStorage.clear on Android --- .../src/org/cocos2dx/lib/Cocos2dxLocalStorage.java | 9 +++++++++ cocos/storage/local-storage/LocalStorage-android.cpp | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxLocalStorage.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxLocalStorage.java index 11eab6f64a..d2dc8e7c04 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxLocalStorage.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxLocalStorage.java @@ -101,6 +101,15 @@ public class Cocos2dxLocalStorage { } } + public static void clear() { + try { + String sql = "delete from "+TABLE_NAME; + mDatabase.execSQL(sql); + } catch (Exception e) { + e.printStackTrace(); + } + } + /** * This creates/opens the database. diff --git a/cocos/storage/local-storage/LocalStorage-android.cpp b/cocos/storage/local-storage/LocalStorage-android.cpp index 67ebc8240e..1854109156 100644 --- a/cocos/storage/local-storage/LocalStorage-android.cpp +++ b/cocos/storage/local-storage/LocalStorage-android.cpp @@ -147,4 +147,16 @@ void localStorageRemoveItem( const std::string& key ) } +/** removes all items from the LS */ +void localStorageClear() +{ + assert( _initialized ); + JniMethodInfo t; + + if (JniHelper::getStaticMethodInfo(t, "org/cocos2dx/lib/Cocos2dxLocalStorage", "clear", "()V")) { + t.env->CallStaticVoidMethod(t.classID, t.methodID); + t.env->DeleteLocalRef(t.classID); + } +} + #endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)