properly dismiss notifications

This commit is contained in:
iNPUTmice 2014-10-02 17:36:02 +02:00
parent fd6f5b0e84
commit 4b09f0e9d3
2 changed files with 25 additions and 10 deletions

View File

@ -120,10 +120,11 @@ public class NotificationService {
+ mXmppConnectionService
.getString(R.string.unread_conversations));
StringBuilder names = new StringBuilder();
Conversation conversation = null;
for (ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) {
String name = messages.get(0).getConversation()
.getName();
conversation = messages.get(0).getConversation();
String name = conversation.getName();
style.addLine(Html.fromHtml("<b>"
+ name
+ "</b> "
@ -142,6 +143,10 @@ public class NotificationService {
.getString(R.string.unread_conversations));
mBuilder.setContentText(names.toString());
mBuilder.setStyle(style);
if (conversation!=null) {
mBuilder.setContentIntent(createContentIntent(conversation
.getUuid()));
}
}
if (notify) {
if (vibrate) {
@ -153,6 +158,7 @@ public class NotificationService {
mBuilder.setSound(Uri.parse(ringtone));
}
}
mBuilder.setDeleteIntent(createDeleteIntent());
mBuilder.setLights(0xffffffff, 2000, 4000);
Notification notification = mBuilder.build();
mNotificationManager.notify(NOTIFICATION_ID, notification);
@ -177,6 +183,12 @@ public class NotificationService {
PendingIntent.FLAG_UPDATE_CURRENT);
return resultPendingIntent;
}
private PendingIntent createDeleteIntent() {
Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
intent.setAction("clear_notification");
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
}
public static boolean wasHighlightedOrPrivate(Message message) {
String nick = message.getConversation().getMucOptions().getActualNick();

View File

@ -90,6 +90,7 @@ public class XmppConnectionService extends Service {
public long startDate;
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
public static String ACTION_CLEAR_NOTIFICATION = "clear_notification";
private MemorizingTrustManager mMemorizingTrustManager;
@ -318,14 +319,16 @@ public class XmppConnectionService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ((intent != null)
&& (ACTION_MERGE_PHONE_CONTACTS.equals(intent.getAction()))) {
mergePhoneContactsWithRoster();
return START_STICKY;
} else if ((intent != null)
&& (Intent.ACTION_SHUTDOWN.equals(intent.getAction()))) {
logoutAndSave();
return START_NOT_STICKY;
if (intent != null && intent.getAction() != null) {
if (intent.getAction().equals(ACTION_MERGE_PHONE_CONTACTS)) {
mergePhoneContactsWithRoster();
return START_STICKY;
} else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
logoutAndSave();
return START_NOT_STICKY;
} else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) {
mNotificationService.clear();
}
}
this.wakeLock.acquire();
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()