From 2d42bc74a69d871e5b92af40cd1a808a71323ddf Mon Sep 17 00:00:00 2001 From: sam-almighty Date: Fri, 19 Jan 2018 14:33:53 +0530 Subject: [PATCH] Updated url end point (#22) * Updated SDK to include BACKGROUND_REFRESH policy for actions * Updated ReadMe for BACKGROUND_REFRESH * Add Destroy method * Included methods to clear cache * Updated url end point --- .../ibm/mobile/applaunch/android/api/AppLaunch.java | 10 ++++------ .../applaunch/android/api/AppLaunchCacheManager.java | 6 ++++++ .../android/internal/AppLaunchUrlBuilder.java | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunch.java b/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunch.java index 13f4e7d..2b33538 100644 --- a/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunch.java +++ b/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunch.java @@ -173,7 +173,6 @@ public void onFailure(AppLaunchFailResponse failResponse) { */ public void destroy(final AppLaunchListener appLaunchListener){ //TODO : Cache Clearing Mechanism and Check device is registered or not - if (appLaunchConfig != null && this.clientSecret != null) { //send all the analytics event to the server sendLogs(); //construct registration url @@ -183,7 +182,7 @@ public void destroy(final AppLaunchListener appLaunchListener){ @Override public void onSuccess(AppLaunchResponse appLaunchResponse) { // Clear all the cache - + appLaunchCacheManager.destroyCache(); } @Override @@ -191,10 +190,9 @@ public void onFailure(AppLaunchFailResponse appLaunchFailResponse) { appLaunchListener.onFailure(appLaunchFailResponse); } }; - sendDeleteRequest(registrationUrl, appLaunchInternalListener); - }else{ - throw new RuntimeException("Invalid Init paramters"); - } + if(appLaunchCacheManager.getString(appLaunchConfig.getUserID()+"-"+appLaunchConfig.getBluemixRegion()+"-"+appLaunchConfig.getApplicationId(),null)!=null){ + sendDeleteRequest(registrationUrl, appLaunchInternalListener); + } } diff --git a/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunchCacheManager.java b/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunchCacheManager.java index 8cb9eab..500f04a 100644 --- a/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunchCacheManager.java +++ b/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/api/AppLaunchCacheManager.java @@ -46,6 +46,12 @@ protected void initializeCache(Context context){ sharedpreferences = context.getSharedPreferences(APP_LAUNCH, Context.MODE_PRIVATE); } + protected void destroyCache(){ + SharedPreferences.Editor editor = getEditor(); + editor.clear(); + editor.commit(); + } + protected String getString(String key, String defaultValue){ if(key!=null){ return sharedpreferences.getString(key,defaultValue); diff --git a/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/internal/AppLaunchUrlBuilder.java b/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/internal/AppLaunchUrlBuilder.java index 6524236..b229ff2 100644 --- a/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/internal/AppLaunchUrlBuilder.java +++ b/AppLaunchClientAndroid/applaunch-client-android/src/main/java/com/ibm/mobile/applaunch/android/internal/AppLaunchUrlBuilder.java @@ -19,8 +19,9 @@ public class AppLaunchUrlBuilder { private static String EVENTS = "/events"; private static String METRICS = "/metrics"; private static String USERS = "/users"; - private static String MOBILESERVICES = "https://mobileservices"; - private static String APPLAUNCH_CONTEXT = "/applaunch/v1"; + private static String MOBILESERVICES = "https://applaunch"; + private static String APPLAUNCH_CONTEXT = "/applaunch/v1"; + public AppLaunchUrlBuilder(ICRegion region, String appID, String deviceID,String userId) { this.baseURL = MOBILESERVICES + region.toString() + APPLAUNCH_CONTEXT;