Trying to fix actions in notification not working
This commit is contained in:
parent
2adca8f90f
commit
68ac6ca680
8 changed files with 67 additions and 12 deletions
|
@ -23,6 +23,7 @@ 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_MARK_AS_READ_ACTION;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_NOTIF_ID;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_REMOTE_IDENTITY;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
||||
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
||||
|
||||
|
@ -132,6 +133,7 @@ class ApiTwentyEightPlus {
|
|||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||
replyIntent.putExtra(INTENT_REMOTE_IDENTITY, notif.getRemoteIdentity());
|
||||
|
||||
PendingIntent replyPendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
|
@ -156,6 +158,7 @@ class ApiTwentyEightPlus {
|
|||
markAsReadIntent.setAction(INTENT_MARK_AS_READ_ACTION);
|
||||
markAsReadIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||
markAsReadIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||
markAsReadIntent.putExtra(INTENT_REMOTE_IDENTITY, notif.getRemoteIdentity());
|
||||
|
||||
PendingIntent markAsReadPendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
|
|
|
@ -25,6 +25,7 @@ import static org.linphone.compatibility.Compatibility.INTENT_HANGUP_CALL_NOTIF_
|
|||
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_REMOTE_IDENTITY;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
||||
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
||||
|
||||
|
@ -167,6 +168,7 @@ class ApiTwentyFourPlus {
|
|||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||
replyIntent.putExtra(INTENT_REMOTE_IDENTITY, notif.getRemoteIdentity());
|
||||
|
||||
PendingIntent replyPendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
|
@ -190,6 +192,7 @@ class ApiTwentyFourPlus {
|
|||
markAsReadIntent.setAction(INTENT_MARK_AS_READ_ACTION);
|
||||
markAsReadIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||
markAsReadIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||
markAsReadIntent.putExtra(INTENT_REMOTE_IDENTITY, notif.getRemoteIdentity());
|
||||
|
||||
PendingIntent markAsReadPendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
|
|
|
@ -24,6 +24,7 @@ import static org.linphone.compatibility.Compatibility.INTENT_HANGUP_CALL_NOTIF_
|
|||
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_REMOTE_IDENTITY;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
||||
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
||||
|
||||
|
@ -48,6 +49,7 @@ public class ApiTwentyNinePlus {
|
|||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||
replyIntent.putExtra(INTENT_REMOTE_IDENTITY, notif.getRemoteIdentity());
|
||||
|
||||
PendingIntent replyPendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
|
@ -72,6 +74,7 @@ public class ApiTwentyNinePlus {
|
|||
markAsReadIntent.setAction(INTENT_MARK_AS_READ_ACTION);
|
||||
markAsReadIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||
markAsReadIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||
markAsReadIntent.putExtra(INTENT_REMOTE_IDENTITY, notif.getRemoteIdentity());
|
||||
|
||||
PendingIntent markAsReadPendingIntent =
|
||||
PendingIntent.getBroadcast(
|
||||
|
|
|
@ -45,6 +45,7 @@ public class Compatibility {
|
|||
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_LOCAL_IDENTITY = "LOCAL_IDENTITY";
|
||||
public static final String INTENT_REMOTE_IDENTITY = "REMOTE_IDENTITY";
|
||||
public static final String INTENT_MARK_AS_READ_ACTION = "org.linphone.MARK_AS_READ_ACTION";
|
||||
|
||||
public static String getDeviceName(Context context) {
|
||||
|
|
|
@ -28,6 +28,7 @@ public class Notifiable {
|
|||
private boolean mIsGroup;
|
||||
private String mGroupTitle;
|
||||
private String mLocalIdentity;
|
||||
private String mRemoteIdentity;
|
||||
private String mMyself;
|
||||
private int mIconId;
|
||||
private int mTextId;
|
||||
|
@ -84,10 +85,18 @@ public class Notifiable {
|
|||
return mLocalIdentity;
|
||||
}
|
||||
|
||||
public String getRemoteIdentity() {
|
||||
return mRemoteIdentity;
|
||||
}
|
||||
|
||||
public void setLocalIdentity(String localIdentity) {
|
||||
mLocalIdentity = localIdentity;
|
||||
}
|
||||
|
||||
public void setRemoteIdentity(String remoteIdentity) {
|
||||
mRemoteIdentity = remoteIdentity;
|
||||
}
|
||||
|
||||
public int getIconResourceId() {
|
||||
return mIconId;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
*/
|
||||
package org.linphone.notifications;
|
||||
|
||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.RemoteInput;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
|
@ -34,27 +37,40 @@ import org.linphone.core.Call;
|
|||
import org.linphone.core.ChatMessage;
|
||||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.core.Factory;
|
||||
import org.linphone.core.tools.Log;
|
||||
import org.linphone.settings.LinphonePreferences;
|
||||
|
||||
public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
final int notifId = intent.getIntExtra(Compatibility.INTENT_NOTIF_ID, 0);
|
||||
final String localyIdentity = intent.getStringExtra(Compatibility.INTENT_LOCAL_IDENTITY);
|
||||
final String remoteIdentity = intent.getStringExtra(Compatibility.INTENT_REMOTE_IDENTITY);
|
||||
|
||||
if (!LinphoneContext.isReady()) {
|
||||
Log.e("[Notification Broadcast Receiver] Context not ready, aborting...");
|
||||
return;
|
||||
Log.e("[Notification Broadcast Receiver] Context not ready...");
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(Compatibility.INTENT_REPLY_NOTIF_ACTION)
|
||||
|| intent.getAction().equals(Compatibility.INTENT_MARK_AS_READ_ACTION)) {
|
||||
String remoteSipAddr =
|
||||
LinphoneContext.instance()
|
||||
.getNotificationManager()
|
||||
.getSipUriForNotificationId(notifId);
|
||||
String remoteSipAddr = remoteIdentity;
|
||||
|
||||
Core core;
|
||||
boolean stopCoreWhenFinished = false;
|
||||
if (!LinphoneContext.isReady()) {
|
||||
String basePath = context.getFilesDir().getAbsolutePath();
|
||||
core =
|
||||
Factory.instance()
|
||||
.createCore(
|
||||
basePath + LinphonePreferences.LINPHONE_DEFAULT_RC,
|
||||
basePath + LinphonePreferences.LINPHONE_FACTORY_RC,
|
||||
context);
|
||||
stopCoreWhenFinished = true;
|
||||
Log.e("[Notification Broadcast Receiver] Created temporary Core");
|
||||
core.start();
|
||||
} else core = LinphoneManager.getCore();
|
||||
|
||||
Core core = LinphoneManager.getCore();
|
||||
if (core == null) {
|
||||
Log.e("[Notification Broadcast Receiver] Couldn't get Core instance");
|
||||
onError(context, notifId);
|
||||
|
@ -102,15 +118,33 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
|
|||
|
||||
ChatMessage msg = room.createMessage(reply);
|
||||
msg.setUserData(notifId);
|
||||
msg.addListener(
|
||||
LinphoneContext.instance().getNotificationManager().getMessageListener());
|
||||
if (!stopCoreWhenFinished) {
|
||||
msg.addListener(
|
||||
LinphoneContext.instance()
|
||||
.getNotificationManager()
|
||||
.getMessageListener());
|
||||
}
|
||||
msg.send();
|
||||
Log.i("[Notification Broadcast Receiver] Reply sent for notif id " + notifId);
|
||||
} else {
|
||||
LinphoneContext.instance().getNotificationManager().dismissNotification(notifId);
|
||||
if (!stopCoreWhenFinished) {
|
||||
LinphoneContext.instance()
|
||||
.getNotificationManager()
|
||||
.dismissNotification(notifId);
|
||||
} else {
|
||||
NotificationManager notificationManager =
|
||||
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(notifId);
|
||||
}
|
||||
}
|
||||
|
||||
if (stopCoreWhenFinished) {
|
||||
core.stopAsync();
|
||||
}
|
||||
} else if (intent.getAction().equals(Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION)
|
||||
|| intent.getAction().equals(Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION)) {
|
||||
if (!LinphoneContext.isReady()) return;
|
||||
|
||||
String remoteAddr =
|
||||
LinphoneContext.instance()
|
||||
.getNotificationManager()
|
||||
|
|
|
@ -462,6 +462,7 @@ public class NotificationsManager {
|
|||
notif.setGroupTitle(subject);
|
||||
notif.setMyself(LinphoneUtils.getAddressDisplayName(localIdentity));
|
||||
notif.setLocalIdentity(localIdentity.asString());
|
||||
notif.setRemoteIdentity(conferenceAddress);
|
||||
|
||||
displayMessageNotificationFromNotifiable(
|
||||
notif, conferenceAddress, localIdentity.asStringUriOnly());
|
||||
|
@ -496,6 +497,7 @@ public class NotificationsManager {
|
|||
notif.setIsGroup(false);
|
||||
notif.setMyself(LinphoneUtils.getAddressDisplayName(localIdentity));
|
||||
notif.setLocalIdentity(localIdentity.asString());
|
||||
notif.setRemoteIdentity(fromSipUri);
|
||||
|
||||
displayMessageNotificationFromNotifiable(
|
||||
notif, fromSipUri, localIdentity.asStringUriOnly());
|
||||
|
|
|
@ -53,8 +53,8 @@ import org.linphone.utils.LinphoneUtils;
|
|||
|
||||
public class LinphonePreferences {
|
||||
private static final int LINPHONE_CORE_RANDOM_PORT = -1;
|
||||
private static final String LINPHONE_DEFAULT_RC = "/.linphonerc";
|
||||
private static final String LINPHONE_FACTORY_RC = "/linphonerc";
|
||||
public static final String LINPHONE_DEFAULT_RC = "/.linphonerc";
|
||||
public static final String LINPHONE_FACTORY_RC = "/linphonerc";
|
||||
private static final String LINPHONE_LPCONFIG_XSD = "/lpconfig.xsd";
|
||||
private static final String DEFAULT_ASSISTANT_RC = "/default_assistant_create.rc";
|
||||
private static final String LINPHONE_ASSISTANT_RC = "/linphone_assistant_create.rc";
|
||||
|
|
Loading…
Reference in a new issue