Notification improvements

This commit is contained in:
Juha Heinanen
2021-10-17 19:10:55 +03:00
parent 11edbd9f14
commit 0a40af648d
@@ -581,21 +581,21 @@ class BaresipService: Service() {
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID) val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
val caller = Utils.friendlyUri(ContactsActivity.contactName(peerUri), val caller = Utils.friendlyUri(ContactsActivity.contactName(peerUri),
Utils.aorDomain(aor)) Utils.aorDomain(aor))
nb.setSmallIcon(R.drawable.ic_stat) nb.setSmallIcon(R.drawable.ic_stat_call)
.setColor(ContextCompat.getColor(this, .setColor(ContextCompat.getColor(this, R.color.colorBaresip))
R.color.colorBaresip))
.setContentIntent(pi) .setContentIntent(pi)
.setCategory(Notification.CATEGORY_CALL) .setCategory(Notification.CATEGORY_CALL)
.setAutoCancel(true) .setAutoCancel(true)
.setOngoing(true) .setOngoing(true)
.setContentTitle(getString(R.string.incoming_call_from)) .setContentTitle(getString(R.string.incoming_call_from))
.setContentText(caller) .setContentText(caller)
.setWhen(System.currentTimeMillis())
.setShowWhen(true) .setShowWhen(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setFullScreenIntent(pi, true) .setFullScreenIntent(pi, true)
if (VERSION.SDK_INT < 26) { if (VERSION.SDK_INT < 26) {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.priority = Notification.PRIORITY_HIGH .priority = Notification.PRIORITY_HIGH
} }
val answerIntent = Intent(applicationContext, MainActivity::class.java) val answerIntent = Intent(applicationContext, MainActivity::class.java)
@@ -616,9 +616,9 @@ class BaresipService: Service() {
else else
PendingIntent.getService(this, REJECT_REQ_CODE, rejectIntent, PendingIntent.getService(this, REJECT_REQ_CODE, rejectIntent,
PendingIntent.FLAG_UPDATE_CURRENT) PendingIntent.FLAG_UPDATE_CURRENT)
nb.addAction(R.drawable.ic_stat, nb.addAction(R.drawable.ic_stat_call,
getActionText(R.string.answer, R.color.colorGreen), api) getActionText(R.string.answer, R.color.colorGreen), api)
nb.addAction(R.drawable.ic_stat, nb.addAction(R.drawable.ic_stat_call_end,
getActionText(R.string.reject, R.color.colorRed), rpi) getActionText(R.string.reject, R.color.colorRed), rpi)
nm.notify(CALL_NOTIFICATION_ID, nb.build()) nm.notify(CALL_NOTIFICATION_ID, nb.build())
return return
@@ -695,7 +695,7 @@ class BaresipService: Service() {
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID) val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
val target = Utils.friendlyUri(ContactsActivity.contactName(ev[1]), val target = Utils.friendlyUri(ContactsActivity.contactName(ev[1]),
Utils.aorDomain(aor)) Utils.aorDomain(aor))
nb.setSmallIcon(R.drawable.ic_stat) nb.setSmallIcon(R.drawable.ic_stat_call)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip)) .setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi) .setContentIntent(pi)
.setDefaults(Notification.DEFAULT_SOUND) .setDefaults(Notification.DEFAULT_SOUND)
@@ -712,7 +712,7 @@ class BaresipService: Service() {
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
acceptIntent.putExtra("action","transfer accept") acceptIntent.putExtra("action","transfer accept")
.putExtra("callp", callp).putExtra("uri", ev[1]) .putExtra("callp", callp).putExtra("uri", ev[1])
val api = if (VERSION.SDK_INT >= 23) val acceptPendingIntent = if (VERSION.SDK_INT >= 23)
PendingIntent.getActivity(applicationContext, ACCEPT_REQ_CODE, PendingIntent.getActivity(applicationContext, ACCEPT_REQ_CODE,
acceptIntent, PendingIntent.FLAG_IMMUTABLE or acceptIntent, PendingIntent.FLAG_IMMUTABLE or
PendingIntent.FLAG_UPDATE_CURRENT) PendingIntent.FLAG_UPDATE_CURRENT)
@@ -724,9 +724,8 @@ class BaresipService: Service() {
denyIntent.putExtra("callp", callp) denyIntent.putExtra("callp", callp)
val denyPendingIntent = PendingIntent.getService(this, val denyPendingIntent = PendingIntent.getService(this,
DENY_REQ_CODE, denyIntent, PendingIntent.FLAG_UPDATE_CURRENT) DENY_REQ_CODE, denyIntent, PendingIntent.FLAG_UPDATE_CURRENT)
nb.addAction(R.drawable.ic_stat, getString(R.string.accept), api) nb.addAction(R.drawable.ic_stat_call, getString(R.string.accept), acceptPendingIntent)
nb.addAction(R.drawable.ic_stat, getString(R.string.deny), nb.addAction(R.drawable.ic_stat_call_end, getString(R.string.deny), denyPendingIntent)
denyPendingIntent)
nm.notify(TRANSFER_NOTIFICATION_ID, nb.build()) nm.notify(TRANSFER_NOTIFICATION_ID, nb.build())
return return
} }
@@ -769,7 +768,7 @@ class BaresipService: Service() {
PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent, PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT) PendingIntent.FLAG_UPDATE_CURRENT)
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID) val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
nb.setSmallIcon(R.drawable.ic_stat) nb.setSmallIcon(R.drawable.ic_stat_phone_missed)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip)) .setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi) .setContentIntent(pi)
.setCategory(Notification.CATEGORY_CALL) .setCategory(Notification.CATEGORY_CALL)
@@ -859,7 +858,7 @@ class BaresipService: Service() {
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID) val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
val sender = Utils.friendlyUri(ContactsActivity.contactName(peer), val sender = Utils.friendlyUri(ContactsActivity.contactName(peer),
Utils.aorDomain(ua.account.aor)) Utils.aorDomain(ua.account.aor))
nb.setSmallIcon(R.drawable.ic_stat) nb.setSmallIcon(R.drawable.ic_stat_message)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip)) .setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi) .setContentIntent(pi)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI) .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
@@ -895,9 +894,9 @@ class BaresipService: Service() {
.putExtra("time", timeStamp) .putExtra("time", timeStamp)
val deletePendingIntent = PendingIntent.getService(this, val deletePendingIntent = PendingIntent.getService(this,
DELETE_REQ_CODE, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT) DELETE_REQ_CODE, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT)
nb.addAction(R.drawable.ic_stat, "Reply", rpi) nb.addAction(R.drawable.ic_stat_reply, "Reply", rpi)
nb.addAction(R.drawable.ic_stat, "Save", savePendingIntent) nb.addAction(R.drawable.ic_stat_save, "Save", savePendingIntent)
nb.addAction(R.drawable.ic_stat, "Delete", deletePendingIntent) nb.addAction(R.drawable.ic_stat_delete, "Delete", deletePendingIntent)
nm.notify(MESSAGE_NOTIFICATION_ID, nb.build()) nm.notify(MESSAGE_NOTIFICATION_ID, nb.build())
return return
} else { } else {