Skip to content

Commit a78d0bf

Browse files
committed
Fixes #100: When a message arrives to Messenger the Call activity is opened by mistake
1 parent b50394c commit a78d0bf

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

Examples/restcomm-messenger/app/src/main/java/com/telestax/restcomm_messenger/MainActivity.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public void onError(Exception exception) {
8181

8282
// TODO: we don't support capability tokens yet so let's use an empty string
8383
device = RCClient.createDevice("", this);
84-
Intent intent = new Intent(getApplicationContext(), CallActivity.class);
85-
device.setIncomingIntent(intent);
84+
device.setPendingIntents(new Intent(getApplicationContext(), CallActivity.class),
85+
new Intent(getApplicationContext(), MainActivity.class));
8686

8787
params = new HashMap<String, String>();
8888

@@ -175,21 +175,6 @@ public void onPresenceChanged(RCDevice device, RCPresenceEvent presenceEvent)
175175

176176
}
177177

178-
public void onIncomingConnection(RCDevice device, RCConnection connection)
179-
{
180-
}
181-
182-
public void onIncomingMessage(RCDevice device, String message, HashMap<String, String> parameters)
183-
{
184-
Log.i(TAG, "Message arrived: " + message);
185-
int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
186-
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
187-
messagePlayer.start();
188-
}
189-
// put new text on the bottom
190-
txtWall.append(parameters.get("username") + ": " + message + "\n");
191-
}
192-
193178
@Override
194179
public void onConfigurationChanged(Configuration newConfig) {
195180
super.onConfigurationChanged(newConfig);
@@ -280,7 +265,7 @@ protected void onResume() {
280265
if (list.size() != 0) {
281266
RCDevice device = list.get(0);
282267
RCConnection pendingConnection = device.getPendingConnection();
283-
onIncomingConnection(device, pendingConnection);
268+
handleIncomingConnection(device, pendingConnection);
284269
}
285270
}
286271
if (intent.getAction() == RCDevice.INCOMING_MESSAGE) {
@@ -290,10 +275,26 @@ protected void onResume() {
290275
RCConnection pendingConnection = device.getPendingConnection();
291276
HashMap<String, String> parms = (HashMap)intent.getSerializableExtra("MESSAGE_PARMS");
292277
String message = (String)intent.getSerializableExtra("MESSAGE");
293-
onIncomingMessage(device, message, parms);
278+
handleIncomingMessage(device, message, parms);
294279
}
295280
}
296281
}
282+
283+
public void handleIncomingConnection(RCDevice device, RCConnection connection)
284+
{
285+
}
286+
287+
public void handleIncomingMessage(RCDevice device, String message, HashMap<String, String> parameters)
288+
{
289+
Log.i(TAG, "Message arrived: " + message);
290+
int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
291+
if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
292+
messagePlayer.start();
293+
}
294+
// put new text on the bottom
295+
txtWall.append(parameters.get("username") + ": " + message + "\n");
296+
}
297+
297298
@Override
298299
protected void onPause() {
299300
super.onPause();

restcomm.android.client.sdk/src/main/java/org/mobicents/restcomm/android/client/sdk/RCDevice.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public enum DeviceCapability {
115115
public static String EXTRA_SDP = "com.telestax.restcomm_messenger.SDP";
116116
//public static String EXTRA_DEVICE = "com.telestax.restcomm.android.client.sdk.extra-device";
117117
//public static String EXTRA_CONNECTION = "com.telestax.restcomm.android.client.sdk.extra-connection";
118-
PendingIntent pendingIntent;
118+
PendingIntent pendingCallIntent;
119+
PendingIntent pendingMessageIntent;
119120
public RCConnection incomingConnection;
120121

121122

@@ -262,8 +263,9 @@ public void setDeviceListener(RCDeviceListener listener) {
262263

263264
}
264265

265-
public void setIncomingIntent(Intent intent) {
266-
pendingIntent = PendingIntent.getActivity(RCClient.getInstance().context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
266+
public void setPendingIntents(Intent callIntent, Intent messageIntent) {
267+
pendingCallIntent = PendingIntent.getActivity(RCClient.getInstance().context, 0, callIntent, PendingIntent.FLAG_UPDATE_CURRENT);
268+
pendingMessageIntent = PendingIntent.getActivity(RCClient.getInstance().context, 0, messageIntent, PendingIntent.FLAG_UPDATE_CURRENT);
267269
}
268270

269271
public RCConnection getPendingConnection() {
@@ -372,7 +374,7 @@ public void run() {
372374
Intent dataIntent = new Intent();
373375
dataIntent.setAction(INCOMING_CALL);
374376
dataIntent.putExtra(RCDevice.EXTRA_DID, from);
375-
pendingIntent.send(RCClient.getInstance().context, 0, dataIntent);
377+
pendingCallIntent.send(RCClient.getInstance().context, 0, dataIntent);
376378

377379
} catch (PendingIntent.CanceledException e) {
378380
e.printStackTrace();
@@ -401,7 +403,7 @@ public void run() {
401403
dataIntent.setAction(INCOMING_MESSAGE);
402404
dataIntent.putExtra("MESSAGE_PARMS", finalParameters);
403405
dataIntent.putExtra("MESSAGE", finalContent);
404-
pendingIntent.send(RCClient.getInstance().context, 0, dataIntent);
406+
pendingMessageIntent.send(RCClient.getInstance().context, 0, dataIntent);
405407
} catch (PendingIntent.CanceledException e) {
406408
e.printStackTrace();
407409
}

restcomm.android.client.sdk/src/main/java/org/mobicents/restcomm/android/client/sdk/RCDeviceListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,21 @@ public interface RCDeviceListener {
5353
*/
5454
public abstract void onStopListening(RCDevice device, int errorCode, String errorText);
5555

56-
// TODO: this should be removed and handled via Android Intents, but to make some tests let's leave it as-is for now
5756
/**
5857
* RCDevice received incoming connection
5958
*
6059
* @param device Device of interest
6160
* @param connection Newly established connection
6261
*/
63-
public abstract void onIncomingConnection(RCDevice device, RCConnection connection);
62+
//public abstract void onIncomingConnection(RCDevice device, RCConnection connection);
6463

6564
/**
6665
* Text message received
6766
* @param device Device of interest
6867
* @param message Tex message
6968
* @param parameters Parameters, such as 'username' designating the username who sent the message
7069
*/
71-
public abstract void onIncomingMessage(RCDevice device, String message, HashMap<String, String> parameters);
70+
//public abstract void onIncomingMessage(RCDevice device, String message, HashMap<String, String> parameters);
7271

7372
/**
7473
* Called to query whether the application wants to retrieve presence events. Return false to indicate that the application isn't interested (<b>Not implemented yet</b>)

0 commit comments

Comments
 (0)