Fix chat notifications + don't display service notification on lock screen on lollipop

This commit is contained in:
Sylvain Berfini 2015-04-17 17:15:33 +02:00
parent 9a606f286f
commit 5b4ab4bc6c
3 changed files with 32 additions and 26 deletions

View file

@ -723,7 +723,9 @@ public class LinphoneManager implements LinphoneCoreListener {
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUserName(), textMessage); LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUserName(), textMessage);
} }
} }
} catch (Exception e) { } } catch (Exception e) {
Log.e(e);
}
} }
public String getLastLcStatusMessage() { public String getLastLcStatusMessage() {

View file

@ -388,18 +388,23 @@ public final class LinphoneService extends Service {
mMsgNotifCount++; mMsgNotifCount++;
} }
Uri pictureUri; Uri pictureUri = null;
try { try {
Contact contact = ContactsManager.getInstance().findContactWithAddress(LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri)); Contact contact = ContactsManager.getInstance().findContactWithAddress(LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri));
pictureUri = contact.getPhotoUri(); if (contact != null)
pictureUri = contact.getPhotoUri();
} catch (LinphoneCoreException e1) { } catch (LinphoneCoreException e1) {
Log.e("Cannot parse from address",e1); Log.e("Cannot parse from address ", e1);
pictureUri=null;
} }
Bitmap bm = null; Bitmap bm = null;
try { if (pictureUri != null) {
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri); try {
} catch (Exception e) { bm = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri);
} catch (Exception e) {
bm = BitmapFactory.decodeResource(getResources(), R.drawable.unknown_small);
}
} else {
bm = BitmapFactory.decodeResource(getResources(), R.drawable.unknown_small); bm = BitmapFactory.decodeResource(getResources(), R.drawable.unknown_small);
} }
mMsgNotif = Compatibility.createMessageNotification(getApplicationContext(), mMsgNotifCount, fromName, message, bm, notifContentIntent); mMsgNotif = Compatibility.createMessageNotification(getApplicationContext(), mMsgNotifCount, fromName, message, bm, notifContentIntent);

View file

@ -7,6 +7,7 @@ import android.app.Notification;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.v4.app.NotificationCompat;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.ViewTreeObserver.OnGlobalLayoutListener;
/* /*
@ -42,20 +43,17 @@ public class ApiTwentyOnePlus {
} else { } else {
title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount)); title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
} }
Notification notif = new Notification.Builder(context) Notification notif = new NotificationCompat.Builder(context)
.setContentTitle(title) .setContentTitle(title)
.setContentText(msg) .setContentText(msg)
.setSmallIcon(R.drawable.chat_icon_over) .setSmallIcon(R.drawable.chat_icon_over)
.setAutoCancel(true) .setAutoCancel(true)
.setContentIntent(intent) .setContentIntent(intent)
.setDefaults(
Notification.DEFAULT_LIGHTS
| Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE)
.setWhen(System.currentTimeMillis())
.setLargeIcon(contactIcon) .setLargeIcon(contactIcon)
.setCategory(Notification.CATEGORY_MESSAGE) .setCategory(Notification.CATEGORY_MESSAGE)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setPriority(Notification.PRIORITY_HIGH)
.build(); .build();
return notif; return notif;
@ -65,15 +63,16 @@ public class ApiTwentyOnePlus {
String title, String msg, int iconID, Bitmap contactIcon, String title, String msg, int iconID, Bitmap contactIcon,
String contactName, PendingIntent intent) { String contactName, PendingIntent intent) {
Notification notif = new Notification.Builder(context).setContentTitle(contactName) Notification notif = new NotificationCompat.Builder(context).setContentTitle(contactName)
.setContentText(msg).setSmallIcon(iconID) .setContentText(msg)
.setSmallIcon(iconID)
.setAutoCancel(false) .setAutoCancel(false)
.setContentIntent(intent) .setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.setLargeIcon(contactIcon) .setLargeIcon(contactIcon)
.setCategory(Notification.CATEGORY_CALL) .setCategory(Notification.CATEGORY_CALL)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setPriority(Notification.PRIORITY_HIGH)
.build(); .build();
notif.flags |= Notification.FLAG_ONGOING_EVENT;
return notif; return notif;
} }
@ -82,27 +81,27 @@ public class ApiTwentyOnePlus {
Notification notif; Notification notif;
if (largeIcon != null) { if (largeIcon != null) {
notif = new Notification.Builder(context) notif = new NotificationCompat.Builder(context)
.setContentTitle(title) .setContentTitle(title)
.setContentText(message) .setContentText(message)
.setSmallIcon(icon, level) .setSmallIcon(icon, level)
.setLargeIcon(largeIcon) .setLargeIcon(largeIcon)
.setContentIntent(intent) .setContentIntent(intent)
.setWhen(System.currentTimeMillis()) .setCategory(Notification.CATEGORY_SERVICE)
.setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_DEFAULT)
.build(); .build();
} else { } else {
notif = new Notification.Builder(context) notif = new NotificationCompat.Builder(context)
.setContentTitle(title) .setContentTitle(title)
.setContentText(message) .setContentText(message)
.setSmallIcon(icon, level) .setSmallIcon(icon, level)
.setContentIntent(intent) .setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.setCategory(Notification.CATEGORY_SERVICE) .setCategory(Notification.CATEGORY_SERVICE)
.setVisibility(Notification.VISIBILITY_SECRET)
.setPriority(Notification.PRIORITY_DEFAULT)
.build(); .build();
} }
if (isOngoingEvent) {
notif.flags |= Notification.FLAG_ONGOING_EVENT;
}
return notif; return notif;
} }