Skip to content

Commit a1f2224

Browse files
committed
Fix NPE when app has low battery
Check for null object from http client getReponse method call. This is a quick way to fix the NPE. In the future investigate why the getReponse call returns null.
1 parent 61c35e5 commit a1f2224

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

smssync/src/main/java/org/addhen/smssync/presentation/presenter/AlertPresenter.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void lowBatteryLevelRequest(int batteryLevel) {
8181
.syncGetByStatus(WebServiceEntity.Status.ENABLED);
8282
if (!Utility.isEmpty(webServiceEntities)) {
8383
for (WebServiceEntity webServiceEntity : webServiceEntities) {
84+
mAppHttpClient.setUrl(webServiceEntity.getUrl());
8485
mAppHttpClient.addParam(TASK_PARAM, "alert");
8586
mAppHttpClient.addParam(MESSAGE_PARAM, mContext.getResources()
8687
.getString(R.string.battery_level_message, batteryLevel));
@@ -90,7 +91,8 @@ public void lowBatteryLevelRequest(int batteryLevel) {
9091
} catch (Exception e) {
9192
mFileManager.appendAndClose(e.getMessage());
9293
} finally {
93-
if (200 == mAppHttpClient.getResponse().code()) {
94+
if ((mAppHttpClient.getResponse()) != null && (200 == mAppHttpClient
95+
.getResponse().code())) {
9496
mFileManager.appendAndClose(
9597
mContext.getResources()
9698
.getString(R.string.successful_alert_to_server));
@@ -113,6 +115,7 @@ public void smsSendFailedRequest(String resultMessage,
113115
List<WebServiceEntity> webServiceEntities = mWebServiceRepository.syncGetByStatus(
114116
WebServiceEntity.Status.ENABLED);
115117
for (WebServiceEntity webServiceEntity : webServiceEntities) {
118+
mAppHttpClient.setUrl(webServiceEntity.getUrl());
116119
mAppHttpClient.addParam(TASK_PARAM, "alert");
117120
mAppHttpClient.addParam(MESSAGE_PARAM, resultMessage);
118121
if (!errorCode.matches("")) {

0 commit comments

Comments
 (0)