Added mark as read notification action for chat messages + refactoring
This commit is contained in:
parent
0e504d2a20
commit
15053ace61
7 changed files with 150 additions and 168 deletions
|
@ -20,53 +20,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static org.linphone.compatibility.Compatibility.CHAT_NOTIFICATIONS_GROUP;
|
import static org.linphone.compatibility.Compatibility.CHAT_NOTIFICATIONS_GROUP;
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_LOCAL_IDENTITY;
|
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_NOTIF_ID;
|
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
|
||||||
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Person;
|
import android.app.Person;
|
||||||
import android.app.RemoteInput;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.notifications.Notifiable;
|
import org.linphone.notifications.Notifiable;
|
||||||
import org.linphone.notifications.NotifiableMessage;
|
import org.linphone.notifications.NotifiableMessage;
|
||||||
import org.linphone.notifications.NotificationBroadcastReceiver;
|
|
||||||
|
|
||||||
@TargetApi(28)
|
@TargetApi(28)
|
||||||
class ApiTwentyEightPlus {
|
class ApiTwentyEightPlus {
|
||||||
public static Notification createMessageNotification(
|
public static Notification createMessageNotification(
|
||||||
Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
||||||
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
|
|
||||||
RemoteInput remoteInput =
|
|
||||||
new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
|
|
||||||
|
|
||||||
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
|
||||||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
|
||||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
|
||||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
|
||||||
|
|
||||||
PendingIntent replyPendingIntent =
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
context,
|
|
||||||
notif.getNotificationId(),
|
|
||||||
replyIntent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
Notification.Action action =
|
|
||||||
new Notification.Action.Builder(
|
|
||||||
R.drawable.chat_send_over,
|
|
||||||
context.getString(R.string.notification_reply_label),
|
|
||||||
replyPendingIntent)
|
|
||||||
.addRemoteInput(remoteInput)
|
|
||||||
.setAllowGeneratedReplies(true)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Person me = new Person.Builder().setName(notif.getMyself()).build();
|
Person me = new Person.Builder().setName(notif.getMyself()).build();
|
||||||
Notification.MessagingStyle style = new Notification.MessagingStyle(me);
|
Notification.MessagingStyle style = new Notification.MessagingStyle(me);
|
||||||
|
@ -105,7 +74,8 @@ class ApiTwentyEightPlus {
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setStyle(style)
|
.setStyle(style)
|
||||||
.addAction(action)
|
.addAction(ApiTwentyFourPlus.getReplyMessageAction(context, notif))
|
||||||
|
.addAction(ApiTwentyFourPlus.getMarkMessageAsReadAction(context, notif))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.linphone.compatibility.Compatibility.CHAT_NOTIFICATIONS_GROUP;
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION;
|
import static org.linphone.compatibility.Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION;
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION;
|
import static org.linphone.compatibility.Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION;
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_LOCAL_IDENTITY;
|
import static org.linphone.compatibility.Compatibility.INTENT_LOCAL_IDENTITY;
|
||||||
|
import static org.linphone.compatibility.Compatibility.INTENT_MARK_AS_READ_ACTION;
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_NOTIF_ID;
|
import static org.linphone.compatibility.Compatibility.INTENT_NOTIF_ID;
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
||||||
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
||||||
|
@ -52,30 +53,6 @@ class ApiTwentyFourPlus {
|
||||||
|
|
||||||
public static Notification createMessageNotification(
|
public static Notification createMessageNotification(
|
||||||
Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
||||||
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
|
|
||||||
RemoteInput remoteInput =
|
|
||||||
new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
|
|
||||||
|
|
||||||
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
|
||||||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
|
||||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
|
||||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
|
||||||
|
|
||||||
PendingIntent replyPendingIntent =
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
context,
|
|
||||||
notif.getNotificationId(),
|
|
||||||
replyIntent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
Notification.Action action =
|
|
||||||
new Notification.Action.Builder(
|
|
||||||
R.drawable.chat_send_over,
|
|
||||||
context.getString(R.string.notification_reply_label),
|
|
||||||
replyPendingIntent)
|
|
||||||
.addRemoteInput(remoteInput)
|
|
||||||
.setAllowGeneratedReplies(true)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Notification.MessagingStyle style = new Notification.MessagingStyle(notif.getMyself());
|
Notification.MessagingStyle style = new Notification.MessagingStyle(notif.getMyself());
|
||||||
for (NotifiableMessage message : notif.getMessages()) {
|
for (NotifiableMessage message : notif.getMessages()) {
|
||||||
|
@ -108,7 +85,8 @@ class ApiTwentyFourPlus {
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setStyle(style)
|
.setStyle(style)
|
||||||
.addAction(action)
|
.addAction(getReplyMessageAction(context, notif))
|
||||||
|
.addAction(getMarkMessageAsReadAction(context, notif))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,14 +100,6 @@ class ApiTwentyFourPlus {
|
||||||
String contactName,
|
String contactName,
|
||||||
PendingIntent intent) {
|
PendingIntent intent) {
|
||||||
|
|
||||||
Intent hangupIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
|
||||||
hangupIntent.setAction(INTENT_HANGUP_CALL_NOTIF_ACTION);
|
|
||||||
hangupIntent.putExtra(INTENT_NOTIF_ID, callId);
|
|
||||||
|
|
||||||
PendingIntent hangupPendingIntent =
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
context, callId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
Notification.Builder builder =
|
Notification.Builder builder =
|
||||||
new Notification.Builder(context)
|
new Notification.Builder(context)
|
||||||
.setContentTitle(contactName)
|
.setContentTitle(contactName)
|
||||||
|
@ -144,12 +114,68 @@ class ApiTwentyFourPlus {
|
||||||
.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(
|
.addAction(getCallDeclineAction(context, callId));
|
||||||
R.drawable.call_hangup,
|
|
||||||
context.getString(R.string.notification_call_hangup_label),
|
|
||||||
hangupPendingIntent);
|
|
||||||
|
|
||||||
if (showAnswerAction) {
|
if (showAnswerAction) {
|
||||||
|
builder.addAction(getCallAnswerAction(context, callId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Notification.Action getReplyMessageAction(Context context, Notifiable notif) {
|
||||||
|
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
|
||||||
|
RemoteInput remoteInput =
|
||||||
|
new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
|
||||||
|
|
||||||
|
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
|
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
||||||
|
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||||
|
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||||
|
|
||||||
|
PendingIntent replyPendingIntent =
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
context,
|
||||||
|
notif.getNotificationId(),
|
||||||
|
replyIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
Notification.Action replyAction =
|
||||||
|
new Notification.Action.Builder(
|
||||||
|
R.drawable.chat_send_over,
|
||||||
|
context.getString(R.string.notification_reply_label),
|
||||||
|
replyPendingIntent)
|
||||||
|
.addRemoteInput(remoteInput)
|
||||||
|
.setAllowGeneratedReplies(true)
|
||||||
|
.build();
|
||||||
|
return replyAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Notification.Action getMarkMessageAsReadAction(
|
||||||
|
Context context, Notifiable notif) {
|
||||||
|
Intent markAsReadIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
|
markAsReadIntent.setAction(INTENT_MARK_AS_READ_ACTION);
|
||||||
|
markAsReadIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||||
|
markAsReadIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||||
|
|
||||||
|
PendingIntent markAsReadPendingIntent =
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
context,
|
||||||
|
notif.getNotificationId(),
|
||||||
|
markAsReadIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
Notification.Action markAsReadAction =
|
||||||
|
new Notification.Action.Builder(
|
||||||
|
R.drawable.chat_send_over,
|
||||||
|
context.getString(R.string.notification_mark_as_read_label),
|
||||||
|
markAsReadPendingIntent)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return markAsReadAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Notification.Action getCallAnswerAction(Context context, int callId) {
|
||||||
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_NOTIF_ID, callId);
|
answerIntent.putExtra(INTENT_NOTIF_ID, callId);
|
||||||
|
@ -158,12 +184,31 @@ class ApiTwentyFourPlus {
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
context, callId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
context, callId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
builder.addAction(
|
Notification.Action answerAction =
|
||||||
|
new Notification.Action.Builder(
|
||||||
R.drawable.call_audio_start,
|
R.drawable.call_audio_start,
|
||||||
context.getString(R.string.notification_call_answer_label),
|
context.getString(R.string.notification_call_answer_label),
|
||||||
answerPendingIntent);
|
answerPendingIntent)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return answerAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
public static Notification.Action getCallDeclineAction(Context context, int callId) {
|
||||||
|
Intent hangupIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
|
hangupIntent.setAction(INTENT_HANGUP_CALL_NOTIF_ACTION);
|
||||||
|
hangupIntent.putExtra(INTENT_NOTIF_ID, callId);
|
||||||
|
|
||||||
|
PendingIntent hangupPendingIntent =
|
||||||
|
PendingIntent.getBroadcast(
|
||||||
|
context, callId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
Notification.Action declineAction =
|
||||||
|
new Notification.Action.Builder(
|
||||||
|
R.drawable.call_hangup,
|
||||||
|
context.getString(R.string.notification_call_hangup_label),
|
||||||
|
hangupPendingIntent)
|
||||||
|
.build();
|
||||||
|
return declineAction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static org.linphone.compatibility.Compatibility.CHAT_NOTIFICATIONS_GROUP;
|
import static org.linphone.compatibility.Compatibility.CHAT_NOTIFICATIONS_GROUP;
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION;
|
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION;
|
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_LOCAL_IDENTITY;
|
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_NOTIF_ID;
|
|
||||||
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
|
||||||
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
|
@ -33,7 +27,6 @@ import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.RemoteInput;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -43,7 +36,6 @@ import android.provider.Settings;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.notifications.Notifiable;
|
import org.linphone.notifications.Notifiable;
|
||||||
import org.linphone.notifications.NotifiableMessage;
|
import org.linphone.notifications.NotifiableMessage;
|
||||||
import org.linphone.notifications.NotificationBroadcastReceiver;
|
|
||||||
|
|
||||||
@TargetApi(26)
|
@TargetApi(26)
|
||||||
class ApiTwentySixPlus {
|
class ApiTwentySixPlus {
|
||||||
|
@ -107,30 +99,6 @@ class ApiTwentySixPlus {
|
||||||
|
|
||||||
public static Notification createMessageNotification(
|
public static Notification createMessageNotification(
|
||||||
Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
||||||
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
|
|
||||||
RemoteInput remoteInput =
|
|
||||||
new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
|
|
||||||
|
|
||||||
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
|
||||||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
|
||||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
|
||||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
|
||||||
|
|
||||||
PendingIntent replyPendingIntent =
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
context,
|
|
||||||
notif.getNotificationId(),
|
|
||||||
replyIntent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
Notification.Action action =
|
|
||||||
new Notification.Action.Builder(
|
|
||||||
R.drawable.chat_send_over,
|
|
||||||
context.getString(R.string.notification_reply_label),
|
|
||||||
replyPendingIntent)
|
|
||||||
.addRemoteInput(remoteInput)
|
|
||||||
.setAllowGeneratedReplies(true)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Notification.MessagingStyle style = new Notification.MessagingStyle(notif.getMyself());
|
Notification.MessagingStyle style = new Notification.MessagingStyle(notif.getMyself());
|
||||||
for (NotifiableMessage message : notif.getMessages()) {
|
for (NotifiableMessage message : notif.getMessages()) {
|
||||||
|
@ -164,7 +132,8 @@ class ApiTwentySixPlus {
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setStyle(style)
|
.setStyle(style)
|
||||||
.addAction(action)
|
.addAction(ApiTwentyFourPlus.getReplyMessageAction(context, notif))
|
||||||
|
.addAction(ApiTwentyFourPlus.getMarkMessageAsReadAction(context, notif))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,14 +147,6 @@ class ApiTwentySixPlus {
|
||||||
String contactName,
|
String contactName,
|
||||||
PendingIntent intent) {
|
PendingIntent intent) {
|
||||||
|
|
||||||
Intent hangupIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
|
||||||
hangupIntent.setAction(INTENT_HANGUP_CALL_NOTIF_ACTION);
|
|
||||||
hangupIntent.putExtra(INTENT_NOTIF_ID, callId);
|
|
||||||
|
|
||||||
PendingIntent hangupPendingIntent =
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
context, callId, hangupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
Notification.Builder builder =
|
Notification.Builder builder =
|
||||||
new Notification.Builder(
|
new Notification.Builder(
|
||||||
context,
|
context,
|
||||||
|
@ -202,24 +163,10 @@ class ApiTwentySixPlus {
|
||||||
.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(
|
.addAction(ApiTwentyFourPlus.getCallDeclineAction(context, callId));
|
||||||
R.drawable.call_hangup,
|
|
||||||
context.getString(R.string.notification_call_hangup_label),
|
|
||||||
hangupPendingIntent);
|
|
||||||
|
|
||||||
if (showAnswerAction) {
|
if (showAnswerAction) {
|
||||||
Intent answerIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
builder.addAction(ApiTwentyFourPlus.getCallAnswerAction(context, callId));
|
||||||
answerIntent.setAction(INTENT_ANSWER_CALL_NOTIF_ACTION);
|
|
||||||
answerIntent.putExtra(INTENT_NOTIF_ID, callId);
|
|
||||||
|
|
||||||
PendingIntent answerPendingIntent =
|
|
||||||
PendingIntent.getBroadcast(
|
|
||||||
context, callId, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
builder.addAction(
|
|
||||||
R.drawable.call_audio_start,
|
|
||||||
context.getString(R.string.notification_call_answer_label),
|
|
||||||
answerPendingIntent);
|
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class Compatibility {
|
||||||
public static final String INTENT_HANGUP_CALL_NOTIF_ACTION = "org.linphone.HANGUP_CALL_ACTION";
|
public static final String INTENT_HANGUP_CALL_NOTIF_ACTION = "org.linphone.HANGUP_CALL_ACTION";
|
||||||
public static final String INTENT_ANSWER_CALL_NOTIF_ACTION = "org.linphone.ANSWER_CALL_ACTION";
|
public static final String INTENT_ANSWER_CALL_NOTIF_ACTION = "org.linphone.ANSWER_CALL_ACTION";
|
||||||
public static final String INTENT_LOCAL_IDENTITY = "LOCAL_IDENTITY";
|
public static final String INTENT_LOCAL_IDENTITY = "LOCAL_IDENTITY";
|
||||||
|
public static final String INTENT_MARK_AS_READ_ACTION = "org.linphone.MARK_AS_READ_ACTION";
|
||||||
|
|
||||||
public static String getDeviceName(Context context) {
|
public static String getDeviceName(Context context) {
|
||||||
if (Version.sdkAboveOrEqual(25)) {
|
if (Version.sdkAboveOrEqual(25)) {
|
||||||
|
|
|
@ -45,13 +45,8 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||||
final int notifId = intent.getIntExtra(Compatibility.INTENT_NOTIF_ID, 0);
|
final int notifId = intent.getIntExtra(Compatibility.INTENT_NOTIF_ID, 0);
|
||||||
final String localyIdentity = intent.getStringExtra(Compatibility.INTENT_LOCAL_IDENTITY);
|
final String localyIdentity = intent.getStringExtra(Compatibility.INTENT_LOCAL_IDENTITY);
|
||||||
|
|
||||||
if (intent.getAction().equals(Compatibility.INTENT_REPLY_NOTIF_ACTION)) {
|
if (intent.getAction().equals(Compatibility.INTENT_REPLY_NOTIF_ACTION)
|
||||||
final String reply = getMessageText(intent).toString();
|
|| intent.getAction().equals(Compatibility.INTENT_MARK_AS_READ_ACTION)) {
|
||||||
if (reply == null) {
|
|
||||||
Log.e("Couldn't get reply text");
|
|
||||||
onError(context, notifId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String remoteSipAddr =
|
String remoteSipAddr =
|
||||||
LinphoneService.instance()
|
LinphoneService.instance()
|
||||||
.getNotificationManager()
|
.getNotificationManager()
|
||||||
|
@ -59,21 +54,25 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
Core core = LinphoneManager.getLc();
|
Core core = LinphoneManager.getLc();
|
||||||
if (core == null) {
|
if (core == null) {
|
||||||
Log.e("Couldn't get Core instance");
|
Log.e("[Notification Broadcast Receiver] Couldn't get Core instance");
|
||||||
onError(context, notifId);
|
onError(context, notifId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Address remoteAddr = core.interpretUrl(remoteSipAddr);
|
Address remoteAddr = core.interpretUrl(remoteSipAddr);
|
||||||
if (remoteAddr == null) {
|
if (remoteAddr == null) {
|
||||||
Log.e("Couldn't interpret remote address " + remoteSipAddr);
|
Log.e(
|
||||||
|
"[Notification Broadcast Receiver] Couldn't interpret remote address "
|
||||||
|
+ remoteSipAddr);
|
||||||
onError(context, notifId);
|
onError(context, notifId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Address localAddr = core.interpretUrl(localyIdentity);
|
Address localAddr = core.interpretUrl(localyIdentity);
|
||||||
if (localAddr == null) {
|
if (localAddr == null) {
|
||||||
Log.e("Couldn't interpret local address " + localyIdentity);
|
Log.e(
|
||||||
|
"[Notification Broadcast Receiver] Couldn't interpret local address "
|
||||||
|
+ localyIdentity);
|
||||||
onError(context, notifId);
|
onError(context, notifId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +80,7 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||||
ChatRoom room = core.findChatRoom(remoteAddr, localAddr);
|
ChatRoom room = core.findChatRoom(remoteAddr, localAddr);
|
||||||
if (room == null) {
|
if (room == null) {
|
||||||
Log.e(
|
Log.e(
|
||||||
"Couldn't find chat room for remote address "
|
"[Notification Broadcast Receiver] Couldn't find chat room for remote address "
|
||||||
+ remoteSipAddr
|
+ remoteSipAddr
|
||||||
+ " and local address "
|
+ " and local address "
|
||||||
+ localyIdentity);
|
+ localyIdentity);
|
||||||
|
@ -95,12 +94,21 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||||
.displayMissedChats(LinphoneManager.getInstance().getUnreadMessageCount());
|
.displayMissedChats(LinphoneManager.getInstance().getUnreadMessageCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (intent.getAction().equals(Compatibility.INTENT_REPLY_NOTIF_ACTION)) {
|
||||||
|
final String reply = getMessageText(intent).toString();
|
||||||
|
if (reply == null) {
|
||||||
|
Log.e("[Notification Broadcast Receiver] Couldn't get reply text");
|
||||||
|
onError(context, notifId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ChatMessage msg = room.createMessage(reply);
|
ChatMessage msg = room.createMessage(reply);
|
||||||
msg.send();
|
msg.send();
|
||||||
msg.setListener(
|
msg.setListener(
|
||||||
new ChatMessageListenerStub() {
|
new ChatMessageListenerStub() {
|
||||||
@Override
|
@Override
|
||||||
public void onMsgStateChanged(ChatMessage msg, ChatMessage.State state) {
|
public void onMsgStateChanged(
|
||||||
|
ChatMessage msg, ChatMessage.State state) {
|
||||||
if (state == ChatMessage.State.Delivered) {
|
if (state == ChatMessage.State.Delivered) {
|
||||||
Notification replied =
|
Notification replied =
|
||||||
Compatibility.createRepliedNotification(context, reply);
|
Compatibility.createRepliedNotification(context, reply);
|
||||||
|
@ -108,11 +116,15 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||||
.getNotificationManager()
|
.getNotificationManager()
|
||||||
.sendNotification(notifId, replied);
|
.sendNotification(notifId, replied);
|
||||||
} else if (state == ChatMessage.State.NotDelivered) {
|
} else if (state == ChatMessage.State.NotDelivered) {
|
||||||
Log.e("Couldn't send reply, message is not delivered");
|
Log.e(
|
||||||
|
"[Notification Broadcast Receiver] Couldn't send reply, message is not delivered");
|
||||||
onError(context, notifId);
|
onError(context, notifId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
LinphoneService.instance().getNotificationManager().dismissNotification(notifId);
|
||||||
|
}
|
||||||
} else if (intent.getAction().equals(Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION)
|
} else if (intent.getAction().equals(Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION)
|
||||||
|| intent.getAction().equals(Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION)) {
|
|| intent.getAction().equals(Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION)) {
|
||||||
String remoteAddr =
|
String remoteAddr =
|
||||||
|
@ -122,12 +134,14 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
Core core = LinphoneManager.getLc();
|
Core core = LinphoneManager.getLc();
|
||||||
if (core == null) {
|
if (core == null) {
|
||||||
Log.e("Couldn't get Core instance");
|
Log.e("[Notification Broadcast Receiver] Couldn't get Core instance");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Call call = core.findCallFromUri(remoteAddr);
|
Call call = core.findCallFromUri(remoteAddr);
|
||||||
if (call == null) {
|
if (call == null) {
|
||||||
Log.e("Couldn't find call from remote address " + remoteAddr);
|
Log.e(
|
||||||
|
"[Notification Broadcast Receiver] Couldn't find call from remote address "
|
||||||
|
+ remoteAddr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -361,4 +361,8 @@ public class NotificationsManager {
|
||||||
pendingIntent);
|
pendingIntent);
|
||||||
sendNotification(IN_APP_NOTIF_ID, notif);
|
sendNotification(IN_APP_NOTIF_ID, notif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dismissNotification(int notifId) {
|
||||||
|
mNM.cancel(notifId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<string name="notification_replied_label">Sent reply: %s</string>
|
<string name="notification_replied_label">Sent reply: %s</string>
|
||||||
<string name="notification_call_hangup_label">Hangup</string>
|
<string name="notification_call_hangup_label">Hangup</string>
|
||||||
<string name="notification_call_answer_label">Answer</string>
|
<string name="notification_call_answer_label">Answer</string>
|
||||||
|
<string name="notification_mark_as_read_label">Mark as read</string>
|
||||||
|
|
||||||
<!-- Common -->
|
<!-- Common -->
|
||||||
<string name="username">Username</string>
|
<string name="username">Username</string>
|
||||||
|
|
Loading…
Reference in a new issue