Blow some breath to your app with Chabok realtime messaging and receive push notifications cross any platform with zero code. Know your users's better, push them content based on their location or track their presence/location withoud headache.
Create chabok account and use chabok credential keys in setting page of sandbox or production panel to init method.
import com.chabokpush.*;
ChabokClient chabok = new ChabokClient(
APP_ID, //Sandbox or Production environment APP_ID
API_KEY, //Sandbox or Production environment API_KEY
USERNAME,//Sandbox or Production environment USERNAME
PASSWORD //Sandbox or Production environment PASSWORD
);
To change chabok enviroment (Sandbox or Production) use setDevelopment
method.
chabok.setDevelopment(true);
chabok.setCallback(new ChabokCallback(){
@Override
public void onConnectError(Throwable cause) {
System.err.println("ConnectError " + cause);
}
@Override
public void onConnect() {
System.out.println("Connected to chabok");
}
@Override
public void onDisconnect(Throwable cause) {
System.out.println("Disconnected " + cause);
}
@Override
public void onMessage(PushMessage message) {
System.out.println("Got message: " + message.toJson());
}
@Override
public void onEvent(EventMessage eventMessage) {
System.out.println("Got event: " + eventMessage);
}
});
For connecting to the chabok use connect
method
chabok.connect("NODE_ID");
PushMessage message = new PushMessage();
message.setUser("*"); //Require, For public channel use *
message.setChannel("CHANNEL_NAME"); //Optional, Channel name.
message.setBody("Hello world..."); //Require.
chabok.publish(message, new Callback() {
@Override
public void onSuccess(Object value) {
System.out.println("Published successfully");
}
@Override
public void onFailure(Throwable value) {
System.err.println("Fail to publish message");
}
});
JSONObject data = new JSONObject();
//Custom data
data.put("tripId", 123456);
data.put("lat",54.2222);
data.put("lng", 32.222);
chabok.publishEvent("shareTrip", data, new Callback() {
@Override
public void onSuccess(Object value) {
System.out.println("Published event successfully");
}
@Override
public void onFailure(Throwable value) {
System.err.println("Fail to publish event");
}
});
chabok.subscribe("private/default", new Callback() {
@Override
public void onSuccess(Object value) {
System.out.println("Subscribe on default channel");
}
@Override
public void onFailure(Throwable value) {
System.err.println("Couldn't subscribe on channel");
}
});
chabok.unsubscribe("private/default", new Callback() {
@Override
public void onSuccess(Object value) {
System.out.println("Unsubscribe to default channel");
}
@Override
public void onFailure(Throwable value) {
System.err.println("Couldn't unsubscribe on channel");
}
});
chabok.subscribeEvent("shareTrip", new Callback() {
@Override
public void onSuccess(Object value) {
System.out.println("Subscribe on shareTrip event");
}
@Override
public void onFailure(Throwable value) {
System.err.println("Couldn't subscribe on shareTrip event");
}
});
chabok.unsubscribeEvent("shareTrip", new Callback() {
@Override
public void onSuccess(Object value) {
System.out.println("Unsubscribe to shareTrip event");
}
@Override
public void onFailure(Throwable value) {
System.err.println("Couldn't unsubscribe on event");
}
});
Please visit Issues.