From f163f569b120e5e2093548a935c56dde7c918bbf Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 28 Jul 2016 21:58:04 +0200 Subject: fix crash on first start --- .../conversations/services/NotificationService.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/services/NotificationService.java') diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index dd708731c..3563100c1 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -523,12 +523,18 @@ public class NotificationService { public Notification createForegroundNotification() { final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService); List accounts = mXmppConnectionService.getAccounts(); - Account mAccount = accounts.get(0); - String status = ""; - if (mAccount.getStatus() == Account.State.ONLINE) { - status = mXmppConnectionService.getString(R.string.account_status_online); - } else if (mAccount.getStatus() == Account.State.CONNECTING) { - status = mXmppConnectionService.getString(R.string.account_status_connecting); + String status; + Account mAccount = null; + Log.d(Config.LOGTAG, "Accounts size " + accounts.size()); + if (accounts.size() > 0) { + mAccount = accounts.get(0); + if (mAccount.getStatus() == Account.State.ONLINE) { + status = mXmppConnectionService.getString(R.string.account_status_online); + } else if (mAccount.getStatus() == Account.State.CONNECTING) { + status = mXmppConnectionService.getString(R.string.account_status_connecting); + } else { + status = mXmppConnectionService.getString(R.string.account_status_offline); + } } else { status = mXmppConnectionService.getString(R.string.account_status_offline); } @@ -557,7 +563,7 @@ public class NotificationService { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setCategory(Notification.CATEGORY_SERVICE); } - if (mAccount.getStatus() == Account.State.ONLINE) { + if (accounts.size() > 0 && mAccount.getStatus() == Account.State.ONLINE) { mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp); } else { mBuilder.setSmallIcon(R.drawable.ic_unlink_white_24dp); -- cgit v1.2.3