Skip to content

Commit

Permalink
Merge pull request #2 from JoaoCaixinha/master
Browse files Browse the repository at this point in the history
Update Realtime messaging SDK to version 2.1.48, set Ortc.setOnPushNo…
  • Loading branch information
João Parreira committed Jun 2, 2015
2 parents 2ad95f9 + c0b4939 commit 98325b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion RTMChat/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.google.android.gms:play-services:6.1.+'
compile 'co.realtime:messaging-android:2.1.34'
compile 'co.realtime:messaging-android:2.1.48'
}
29 changes: 20 additions & 9 deletions RTMChat/app/src/main/java/services/MyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ibt.ortc.extensibility.OnConnected;
import ibt.ortc.extensibility.OnException;
import ibt.ortc.extensibility.OnMessage;
import ibt.ortc.extensibility.OnMessageWithPayload;
import ibt.ortc.extensibility.OrtcClient;
import ibt.ortc.extensibility.OrtcFactory;
import rtmchat.realtime.co.rtmchat.R;
Expand All @@ -20,6 +21,8 @@
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import java.util.Map;

public class MyService extends Service {

private static final String TAG = "MyService";
Expand All @@ -36,18 +39,26 @@ public void onCreate() {
factory = ortc.loadOrtcFactory("IbtRealtimeSJ");
client = factory.createClient();
client.setHeartbeatActive(true);
Ortc.setOnPushNotification(new OnMessage() {
Ortc.setOnPushNotification(new OnMessageWithPayload() {
@Override
public void run(OrtcClient sender, final String channel, final String message) {
Log.i(TAG, String.format("Push notification on channel %s: %s", channel, message));
if(!MessageActivity.isInForeground() && !NotificationActivity.isInForeground()) {
String parts [] = message.split(":");
String user = parts[0].split("_")[parts[0].split("_").length - 1];
String msg = parts[1];
displayNotification(channel, user,msg);
}
public void run(OrtcClient sender, final String channel, final String message, Map<String, Object> payload) {

if(payload != null) {
Log.i(TAG, String.format("Push notification on channel %s: %s payload: %s", channel, message, payload.toString()));
}else{
Log.i(TAG, String.format("Push notification on channel %s: %s ", channel, message));
}

if(!MessageActivity.isInForeground() && !NotificationActivity.isInForeground()) {
String parts [] = message.split(":");
String user = parts[0].split("_")[parts[0].split("_").length - 1];
String msg = parts[1];
displayNotification(channel, user,msg);
}

}
});

client.setApplicationContext(getApplicationContext());
client.setGoogleProjectId(Config.PROJECT_ID);
} catch (Exception e) {
Expand Down

0 comments on commit 98325b6

Please sign in to comment.