diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7b0921ff8d90402ed79bb5f245a2348993ece359..f7d7185b04799440fc232b3ffd10ef632e76220c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,9 @@ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.USB_PERMISSION" /> + <!-- allow to disable battery optimization --> + <uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> + <application android:name=".UploaderApplication" android:allowBackup="true" @@ -26,8 +29,6 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - <!-- allow to disable battery optimization --> - <uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> <!-- I have set screenOrientation to "portrait" to avoid the restart of AsyncTasks when you rotate the phone --> <activity diff --git a/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java b/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java index ff4bb71d4a17ffaa7260bcf21ae4c95baffb1527..b542315ff5d471d0dee874e0a08da76ebffe2f75 100644 --- a/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java +++ b/app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java @@ -10,6 +10,8 @@ import android.preference.PreferenceManager; import android.support.v4.content.LocalBroadcastManager; import android.util.Log; +import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; import org.apache.http.client.ResponseHandler; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; @@ -169,22 +171,22 @@ public class NightscoutUploadIntentService extends IntentService { addMbgEntry(entriesBody, record); } - uploadToNightscout(new URL(baseURL + "/entries"), secret, entriesBody); + boolean isUploaded = uploadToNightscout(new URL(baseURL + "/entries"), secret, entriesBody); - for(int i = 0; i < devicestatusBody.length(); i++) { - uploadToNightscout(new URL(baseURL + "/devicestatus"), secret, devicestatusBody.getJSONObject(i)); + for(int i = 0; isUploaded && i < devicestatusBody.length(); i++) { + isUploaded &= uploadToNightscout(new URL(baseURL + "/devicestatus"), secret, devicestatusBody.getJSONObject(i)); } - // Yay! We uploaded. Tell Realm - // FIXME - check the upload succeeded! - mRealm.beginTransaction(); - - for (PumpStatusEvent updateRecord : records) { - updateRecord.setUploaded(true); + if (isUploaded) { + // Yay! We uploaded. Tell Realm + // FIXME - check the upload succeeded! + mRealm.beginTransaction(); + for (PumpStatusEvent updateRecord : records) { + updateRecord.setUploaded(true); + } + mRealm.commitTransaction(); } - mRealm.commitTransaction(); - } catch (Exception e) { Log.e(TAG, "Unable to post data", e); } @@ -236,6 +238,7 @@ public class NightscoutUploadIntentService extends IntentService { httpclient.execute(post, responseHandler); } catch (Exception e) { Log.w(TAG, "Unable to post data to: '" + post.getURI().toString() + "'", e); + return false; } return true;