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.
|
||||
- Send SMS to invite your friends in using Linphone.
|
||||
- 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
|
||||
|
||||
|
|
|
@ -511,7 +511,6 @@ public final class LinphoneService extends Service {
|
|||
Address address = call.getRemoteAddress();
|
||||
String addressAsString = address.asStringUriOnly();
|
||||
Notified notif = mCallNotifMap.get(addressAsString);
|
||||
|
||||
if (notif == null) {
|
||||
notif = new Notified();
|
||||
notif.notificationId = mLastNotificationId;
|
||||
|
@ -519,18 +518,22 @@ public final class LinphoneService extends Service {
|
|||
mCallNotifMap.put(addressAsString, notif);
|
||||
}
|
||||
|
||||
int notificationTextId = 0;
|
||||
int inconId = 0;
|
||||
if (!displayServiceNotification()) {
|
||||
if (call.getCore().getCallsNb() == 0) {
|
||||
hideServiceNotification();
|
||||
} else {
|
||||
showServiceNotification();
|
||||
}
|
||||
}
|
||||
|
||||
int notificationTextId;
|
||||
int inconId;
|
||||
switch (call.getState()) {
|
||||
case Released:
|
||||
case End:
|
||||
if (!displayServiceNotification()) {
|
||||
stopForegroundCompat(notif.notificationId);
|
||||
} else {
|
||||
mNM.cancel(notif.notificationId);
|
||||
}
|
||||
mCallNotifMap.remove(addressAsString);
|
||||
break;
|
||||
return;
|
||||
case Paused:
|
||||
case PausedByRemote:
|
||||
case Pausing:
|
||||
|
@ -558,18 +561,14 @@ public final class LinphoneService extends Service {
|
|||
}
|
||||
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);
|
||||
notifIntent.putExtra("Notification", true);
|
||||
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()) {
|
||||
startForegroundCompat(notif.notificationId, notification);
|
||||
} else {
|
||||
notifyWrapper(notif.notificationId, notification);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSipUriForCallNotificationId(int notificationId) {
|
||||
for (String addr : mCallNotifMap.keySet()) {
|
||||
|
@ -734,8 +733,6 @@ public final class LinphoneService extends Service {
|
|||
invokeMethod(mStartForeground, mStartForegroundArgs);
|
||||
return;
|
||||
}
|
||||
|
||||
notifyWrapper(id, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -749,10 +746,6 @@ public final class LinphoneService extends Service {
|
|||
invokeMethod(mStopForeground, mStopForegroundArgs);
|
||||
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() {
|
||||
|
|
|
@ -96,7 +96,14 @@ public class ApiTwentyFourPlus {
|
|||
}
|
||||
|
||||
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)
|
||||
.setContentTitle(contactName)
|
||||
|
@ -110,16 +117,10 @@ public class ApiTwentyFourPlus {
|
|||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setShowWhen(true)
|
||||
.setColor(context.getColor(R.color.notification_color_led));
|
||||
|
||||
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);
|
||||
.setColor(context.getColor(R.color.notification_color_led))
|
||||
.addAction(R.drawable.call_hangup, context.getString(R.string.notification_call_hangup_label), hangupPendingIntent);
|
||||
|
||||
if (showAnswerAction) {
|
||||
Intent answerIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||
answerIntent.setAction(INTENT_ANSWER_CALL_NOTIF_ACTION);
|
||||
answerIntent.putExtra(INTENT_CALL_ID, callId);
|
||||
|
@ -127,7 +128,6 @@ public class ApiTwentyFourPlus {
|
|||
PendingIntent answerPendingIntent = PendingIntent.getBroadcast(context,
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,14 @@ public class ApiTwentySixPlus {
|
|||
}
|
||||
|
||||
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))
|
||||
.setContentTitle(contactName)
|
||||
|
@ -141,17 +148,10 @@ public class ApiTwentySixPlus {
|
|||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setShowWhen(true)
|
||||
.setColor(context.getColor(R.color.notification_color_led));
|
||||
|
||||
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);
|
||||
.setColor(context.getColor(R.color.notification_color_led))
|
||||
.addAction(R.drawable.call_hangup, context.getString(R.string.notification_call_hangup_label), hangupPendingIntent);
|
||||
|
||||
if (showAnswerAction) {
|
||||
Intent answerIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||
answerIntent.setAction(INTENT_ANSWER_CALL_NOTIF_ACTION);
|
||||
answerIntent.putExtra(INTENT_CALL_ID, callId);
|
||||
|
@ -159,7 +159,6 @@ public class ApiTwentySixPlus {
|
|||
PendingIntent answerPendingIntent = PendingIntent.getBroadcast(context,
|
||||
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);
|
||||
}
|
||||
return builder.build();
|
||||
|
|
|
@ -98,11 +98,11 @@ public class Compatibility {
|
|||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
return ApiTwentyOnePlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
} 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) {
|
||||
call.accept();
|
||||
} else {
|
||||
call.decline(Reason.None);
|
||||
call.terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue