Always keep hangup action in call notification + fixed multiple call notifications issue
This commit is contained in:
parent
82a81e5d5d
commit
1491cb9710
6 changed files with 53 additions and 61 deletions
|
@ -32,7 +32,7 @@ Group changes to describe their impact on the project, as follows:
|
||||||
- Use TextureView instead of GL2JNIView, easier to use and will fix issues.
|
- Use TextureView instead of GL2JNIView, easier to use and will fix issues.
|
||||||
- Send SMS to invite your friends in using Linphone.
|
- Send SMS to invite your friends in using Linphone.
|
||||||
- Reply to received chat message in notification.
|
- Reply to received chat message in notification.
|
||||||
- Answer or hangup incoming call in notification.
|
- Answer or hangup calls in notification.
|
||||||
|
|
||||||
## [4.0.1] - 2018-06-26
|
## [4.0.1] - 2018-06-26
|
||||||
|
|
||||||
|
|
|
@ -511,7 +511,6 @@ public final class LinphoneService extends Service {
|
||||||
Address address = call.getRemoteAddress();
|
Address address = call.getRemoteAddress();
|
||||||
String addressAsString = address.asStringUriOnly();
|
String addressAsString = address.asStringUriOnly();
|
||||||
Notified notif = mCallNotifMap.get(addressAsString);
|
Notified notif = mCallNotifMap.get(addressAsString);
|
||||||
|
|
||||||
if (notif == null) {
|
if (notif == null) {
|
||||||
notif = new Notified();
|
notif = new Notified();
|
||||||
notif.notificationId = mLastNotificationId;
|
notif.notificationId = mLastNotificationId;
|
||||||
|
@ -519,18 +518,22 @@ public final class LinphoneService extends Service {
|
||||||
mCallNotifMap.put(addressAsString, notif);
|
mCallNotifMap.put(addressAsString, notif);
|
||||||
}
|
}
|
||||||
|
|
||||||
int notificationTextId = 0;
|
if (!displayServiceNotification()) {
|
||||||
int inconId = 0;
|
if (call.getCore().getCallsNb() == 0) {
|
||||||
|
hideServiceNotification();
|
||||||
|
} else {
|
||||||
|
showServiceNotification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int notificationTextId;
|
||||||
|
int inconId;
|
||||||
switch (call.getState()) {
|
switch (call.getState()) {
|
||||||
case Released:
|
case Released:
|
||||||
case End:
|
case End:
|
||||||
if (!displayServiceNotification()) {
|
mNM.cancel(notif.notificationId);
|
||||||
stopForegroundCompat(notif.notificationId);
|
|
||||||
} else {
|
|
||||||
mNM.cancel(notif.notificationId);
|
|
||||||
}
|
|
||||||
mCallNotifMap.remove(addressAsString);
|
mCallNotifMap.remove(addressAsString);
|
||||||
break;
|
return;
|
||||||
case Paused:
|
case Paused:
|
||||||
case PausedByRemote:
|
case PausedByRemote:
|
||||||
case Pausing:
|
case Pausing:
|
||||||
|
@ -558,17 +561,13 @@ public final class LinphoneService extends Service {
|
||||||
}
|
}
|
||||||
String name = LinphoneUtils.getAddressDisplayName(address);
|
String name = LinphoneUtils.getAddressDisplayName(address);
|
||||||
|
|
||||||
boolean showActions = call.getState() == State.IncomingReceived || call.getState() == State.IncomingEarlyMedia;
|
boolean showAnswerAction = call.getState() == State.IncomingReceived || call.getState() == State.IncomingEarlyMedia;
|
||||||
Intent notifIntent = new Intent(this, incomingReceivedActivity);
|
Intent notifIntent = new Intent(this, incomingReceivedActivity);
|
||||||
notifIntent.putExtra("Notification", true);
|
notifIntent.putExtra("Notification", true);
|
||||||
mNotifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
mNotifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
Notification notification = Compatibility.createInCallNotification(getApplicationContext(), notif.notificationId, showActions, mNotificationTitle, getString(notificationTextId), inconId, bm, name, mNotifContentIntent);
|
Notification notification = Compatibility.createInCallNotification(getApplicationContext(), notif.notificationId, showAnswerAction, mNotificationTitle, getString(notificationTextId), inconId, bm, name, mNotifContentIntent);
|
||||||
|
|
||||||
if (!displayServiceNotification()) {
|
notifyWrapper(notif.notificationId, notification);
|
||||||
startForegroundCompat(notif.notificationId, notification);
|
|
||||||
} else {
|
|
||||||
notifyWrapper(notif.notificationId, notification);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSipUriForCallNotificationId(int notificationId) {
|
public String getSipUriForCallNotificationId(int notificationId) {
|
||||||
|
@ -734,8 +733,6 @@ public final class LinphoneService extends Service {
|
||||||
invokeMethod(mStartForeground, mStartForegroundArgs);
|
invokeMethod(mStartForeground, mStartForegroundArgs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyWrapper(id, notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -749,10 +746,6 @@ public final class LinphoneService extends Service {
|
||||||
invokeMethod(mStopForeground, mStopForegroundArgs);
|
invokeMethod(mStopForeground, mStopForegroundArgs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back on the old API. Note to cancel BEFORE changing the
|
|
||||||
// foreground state, since we could be killed at that point.
|
|
||||||
mNM.cancel(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dumpDeviceInformation() {
|
private void dumpDeviceInformation() {
|
||||||
|
|
|
@ -96,7 +96,14 @@ public class ApiTwentyFourPlus {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createInCallNotification(Context context,
|
public static Notification createInCallNotification(Context context,
|
||||||
int callId, boolean showActions, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
int callId, boolean showAnswerAction, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
||||||
|
|
||||||
|
Intent hangupIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
|
hangupIntent.setAction(INTENT_HANGUP_CALL_NOTIF_ACTION);
|
||||||
|
hangupIntent.putExtra(INTENT_CALL_ID, callId);
|
||||||
|
|
||||||
|
PendingIntent hangupPendingIntent = PendingIntent.getBroadcast(context,
|
||||||
|
callId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
Notification.Builder builder = new Notification.Builder(context)
|
Notification.Builder builder = new Notification.Builder(context)
|
||||||
.setContentTitle(contactName)
|
.setContentTitle(contactName)
|
||||||
|
@ -110,16 +117,10 @@ public class ApiTwentyFourPlus {
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColor(context.getColor(R.color.notification_color_led));
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
|
.addAction(R.drawable.call_hangup, context.getString(R.string.notification_call_hangup_label), hangupPendingIntent);
|
||||||
if (showActions) {
|
|
||||||
Intent hangupIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
|
||||||
hangupIntent.setAction(INTENT_HANGUP_CALL_NOTIF_ACTION);
|
|
||||||
hangupIntent.putExtra(INTENT_CALL_ID, callId);
|
|
||||||
|
|
||||||
PendingIntent hangupPendingIntent = PendingIntent.getBroadcast(context,
|
|
||||||
callId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
|
if (showAnswerAction) {
|
||||||
Intent answerIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
Intent answerIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
answerIntent.setAction(INTENT_ANSWER_CALL_NOTIF_ACTION);
|
answerIntent.setAction(INTENT_ANSWER_CALL_NOTIF_ACTION);
|
||||||
answerIntent.putExtra(INTENT_CALL_ID, callId);
|
answerIntent.putExtra(INTENT_CALL_ID, callId);
|
||||||
|
@ -127,7 +128,6 @@ public class ApiTwentyFourPlus {
|
||||||
PendingIntent answerPendingIntent = PendingIntent.getBroadcast(context,
|
PendingIntent answerPendingIntent = PendingIntent.getBroadcast(context,
|
||||||
callId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
callId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
builder.addAction(R.drawable.call_hangup, context.getString(R.string.notification_call_hangup_label), hangupPendingIntent);
|
|
||||||
builder.addAction(R.drawable.call_audio_start, context.getString(R.string.notification_call_answer_label), answerPendingIntent);
|
builder.addAction(R.drawable.call_audio_start, context.getString(R.string.notification_call_answer_label), answerPendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,31 +127,31 @@ public class ApiTwentySixPlus {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createInCallNotification(Context context,
|
public static Notification createInCallNotification(Context context,
|
||||||
int callId, boolean showActions, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
int callId, boolean showAnswerAction, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
||||||
|
|
||||||
|
Intent hangupIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
|
hangupIntent.setAction(INTENT_HANGUP_CALL_NOTIF_ACTION);
|
||||||
|
hangupIntent.putExtra(INTENT_CALL_ID, callId);
|
||||||
|
|
||||||
|
PendingIntent hangupPendingIntent = PendingIntent.getBroadcast(context,
|
||||||
|
callId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
Notification.Builder builder = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
Notification.Builder builder = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
||||||
.setContentTitle(contactName)
|
.setContentTitle(contactName)
|
||||||
.setContentText(msg)
|
.setContentText(msg)
|
||||||
.setSmallIcon(iconID)
|
.setSmallIcon(iconID)
|
||||||
.setAutoCancel(false)
|
.setAutoCancel(false)
|
||||||
.setContentIntent(intent)
|
.setContentIntent(intent)
|
||||||
.setLargeIcon(contactIcon)
|
.setLargeIcon(contactIcon)
|
||||||
.setCategory(Notification.CATEGORY_CALL)
|
.setCategory(Notification.CATEGORY_CALL)
|
||||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColor(context.getColor(R.color.notification_color_led));
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
|
.addAction(R.drawable.call_hangup, context.getString(R.string.notification_call_hangup_label), hangupPendingIntent);
|
||||||
if (showActions) {
|
|
||||||
|
|
||||||
Intent hangupIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
|
||||||
hangupIntent.setAction(INTENT_HANGUP_CALL_NOTIF_ACTION);
|
|
||||||
hangupIntent.putExtra(INTENT_CALL_ID, callId);
|
|
||||||
|
|
||||||
PendingIntent hangupPendingIntent = PendingIntent.getBroadcast(context,
|
|
||||||
callId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
|
if (showAnswerAction) {
|
||||||
Intent answerIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
Intent answerIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
answerIntent.setAction(INTENT_ANSWER_CALL_NOTIF_ACTION);
|
answerIntent.setAction(INTENT_ANSWER_CALL_NOTIF_ACTION);
|
||||||
answerIntent.putExtra(INTENT_CALL_ID, callId);
|
answerIntent.putExtra(INTENT_CALL_ID, callId);
|
||||||
|
@ -159,7 +159,6 @@ public class ApiTwentySixPlus {
|
||||||
PendingIntent answerPendingIntent = PendingIntent.getBroadcast(context,
|
PendingIntent answerPendingIntent = PendingIntent.getBroadcast(context,
|
||||||
callId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
callId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
builder.addAction(R.drawable.call_hangup, context.getString(R.string.notification_call_hangup_label), hangupPendingIntent);
|
|
||||||
builder.addAction(R.drawable.call_audio_start, context.getString(R.string.notification_call_answer_label), answerPendingIntent);
|
builder.addAction(R.drawable.call_audio_start, context.getString(R.string.notification_call_answer_label), answerPendingIntent);
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
|
@ -98,11 +98,11 @@ public class Compatibility {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createInCallNotification(Context context, int callId, boolean showActions, String title, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
public static Notification createInCallNotification(Context context, int callId, boolean showAnswerAction, String title, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||||
return ApiTwentySixPlus.createInCallNotification(context, callId, showActions, msg, iconID, contactIcon, contactName, intent);
|
return ApiTwentySixPlus.createInCallNotification(context, callId, showAnswerAction, msg, iconID, contactIcon, contactName, intent);
|
||||||
} else if (Version.sdkAboveOrEqual(Version.API24_NOUGAT_70)) {
|
} else if (Version.sdkAboveOrEqual(Version.API24_NOUGAT_70)) {
|
||||||
return ApiTwentyFourPlus.createInCallNotification(context, callId, showActions, msg, iconID, contactIcon, contactName, intent);
|
return ApiTwentyFourPlus.createInCallNotification(context, callId, showAnswerAction, msg, iconID, contactIcon, contactName, intent);
|
||||||
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||||
return ApiTwentyOnePlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
return ApiTwentyOnePlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||||
if (intent.getAction() == Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION) {
|
if (intent.getAction() == Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION) {
|
||||||
call.accept();
|
call.accept();
|
||||||
} else {
|
} else {
|
||||||
call.decline(Reason.None);
|
call.terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue