From 3699e02c209a50d9d835a4d0e2d7dd9a9bbcfa83 Mon Sep 17 00:00:00 2001 From: Peter De Jonckheere <peter.de-jonckheere.2014@uni.strath.ac.uk> Date: Tue, 14 Aug 2018 11:07:30 +0100 Subject: [PATCH] Attempt to fix occasional crashes --- .../sedentary/frontEnd/SaveFile.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java index bf23906..6f845e4 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java @@ -14,6 +14,7 @@ import com.google.android.gms.awareness.snapshot.LocationResponse; import com.google.android.gms.awareness.snapshot.PlacesResponse; import com.google.android.gms.awareness.snapshot.WeatherResponse; import com.google.android.gms.awareness.state.Weather; +import com.google.android.gms.common.api.ApiException; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.places.Place; import com.google.android.gms.location.places.PlaceLikelihood; @@ -193,7 +194,11 @@ public class SaveFile { } } recordTimeStamp(sent, clicked, movement, acknowledged, context); - getExtraData(context); + try { + getExtraData(context); + }catch(ApiException e){ + + } if(sent == 1 || acknowledged == 1){ DataAnalysis.placeAnalysis(context); } @@ -306,7 +311,7 @@ public class SaveFile { } - public static void recordData(Context context) { + public static void recordData(Context context) { SharedPreferences preferences = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE); double latitude = Double.longBitsToDouble(preferences.getLong(context.getString(R.string.store_lat), 0)); @@ -368,7 +373,7 @@ public class SaveFile { } - private static void getExtraData(final Context context){ + private static void getExtraData(final Context context) throws ApiException{ GoogleApiClient client; client = new GoogleApiClient.Builder(context) .addApi(Awareness.getSnapshotClient(context).getApi()).build(); @@ -386,8 +391,8 @@ public class SaveFile { SharedPreferences preferences = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); - editor.putLong(context.getString(R.string.store_lat), Double.doubleToLongBits(task.getResult().getLocation().getLatitude())); - editor.putLong(context.getString(R.string.store_long), Double.doubleToLongBits(task.getResult().getLocation().getLongitude())); + editor.putLong(context.getString(R.string.store_lat), Double.doubleToLongBits(task.getResult().getLocation().getLatitude())); + editor.putLong(context.getString(R.string.store_long), Double.doubleToLongBits(task.getResult().getLocation().getLongitude())); editor.commit(); } -- GitLab