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);
}
}
} catch (Exception e) { }
} catch (Exception e) {
Log.e(e);
}
}
public String getLastLcStatusMessage() {

View file

@ -388,20 +388,25 @@ public final class LinphoneService extends Service {
mMsgNotifCount++;
}
Uri pictureUri;
Uri pictureUri = null;
try {
Contact contact = ContactsManager.getInstance().findContactWithAddress(LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri));
if (contact != null)
pictureUri = contact.getPhotoUri();
} catch (LinphoneCoreException e1) {
Log.e("Cannot parse from address ", e1);
pictureUri=null;
}
Bitmap bm = null;
if (pictureUri != null) {
try {
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);
}
mMsgNotif = Compatibility.createMessageNotification(getApplicationContext(), mMsgNotifCount, fromName, message, bm, notifContentIntent);
notifyWrapper(MESSAGE_NOTIF_ID, mMsgNotif);

View file

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