forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublishExample.java
More file actions
79 lines (64 loc) · 2.59 KB
/
Copy pathPublishExample.java
File metadata and controls
79 lines (64 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package examples;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONObject;
import pubnub.Pubnub;
public class PublishExample {
@SuppressWarnings("static-access")
public static void main(String[] params) {
String pub_key = "demo", sub_key = "demo";
String secret_key = "demo", cipher_key = ""; //(Cipher key is Optional)
String channel = "hello_world"; // "c2dmalt"; "androidsample";
int publish_messages_count = 1;
Pubnub pubnub = new Pubnub(pub_key, sub_key, secret_key, cipher_key, true); //(Cipher key is Optional)
int count = 0;
while (true) {
if (count < publish_messages_count) {
count++;
// Create JSON Message
JSONObject message = new JSONObject();
try {
message.put("some_val", "Hello World! --> ɂ顶@#$%^&*()!"+ count);
/*
* message.put( "title", "Android PubNub"); message.put(
* "text", "This is a push to all users! woot!");
* message.put( "url", "http://www.pubnub.com");
*/
} catch (org.json.JSONException jsonError) {
}
// Publish
HashMap<String, Object> args = new HashMap<String, Object>(2);
args.put("channel", channel);
args.put("message", message);
JSONArray response = null;
response = pubnub.publish(args);
System.out.println(response);
args = new HashMap<String, Object>(2);
args.put("channel", channel);
args.put("message", "Hello World");
response = pubnub.publish(args);
System.out.println(response);
JSONArray array = new JSONArray();
array.put("Sunday");
array.put("Monday");
array.put("Tuesday");
array.put("Wednesday");
array.put("Thursday");
array.put("Friday");
array.put("Saturday");
args = new HashMap<String, Object>(2);
args.put("channel", channel);
args.put("message", array);
response = pubnub.publish(args);
System.out.println(response);
// Pause
try {
Thread.currentThread().sleep(100);
} catch (Exception ex) {
}
} else {
break;
}
}
}
}