Permalink
Browse files

Android: updated User-Agent to Java-Android and tab spaces correction

  • Loading branch information...
1 parent ae0590e commit 7b36df6692a8471ad4390187b7f7120d334cc963 raju committed Jun 15, 2012
@@ -611,7 +611,6 @@ private JSONArray _request(List<String> url_components) {
try { jsono.put("Failed JSONP HTTP Request."); }
catch (Exception jsone) {}
- e.printStackTrace();
System.out.println(e);
return jsono;
@@ -648,7 +647,7 @@ public String call() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
HttpUriRequest request = new HttpGet(url);
request.setHeader("V", "3.1");
- request.setHeader("User-Agent", "Android");
+ request.setHeader("User-Agent", "Java-Android");
request.setHeader("Accept-Encoding", "gzip");
httpclient.getParams().setParameter("http.connection.timeout", 310000);
@@ -66,13 +66,10 @@ private void generateNotification(Context context, String title,
// Launch new Intent to view a new contact added
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, uri);
- PendingIntent contentIntent = PendingIntent.getActivity(
- getApplicationContext(), 0, notificationIntent, 0);
- notification.setLatestEventInfo(getApplicationContext(), title,
- message, contentIntent);
+ PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
+ notification.setLatestEventInfo(getApplicationContext(), title, message, contentIntent);
- NotificationManager nm = (NotificationManager) context
- .getSystemService(Context.NOTIFICATION_SERVICE);
+ NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, notification);
}
@@ -82,9 +79,9 @@ public boolean execute(Object message) {
if(message instanceof JSONObject)
{
JSONObject message1 =(JSONObject)message;
- generateNotification(getApplicationContext(),
- message1.getString("title"), message1.getString("text"),
- Uri.parse(message1.getString("url")));
+ generateNotification(getApplicationContext(),
+ message1.getString("title"), message1.getString("text"),
+ Uri.parse(message1.getString("url")));
}
} catch (Exception e) {
e.printStackTrace();
@@ -99,53 +96,53 @@ public boolean execute(Object message) {
protected Boolean doInBackground(String... params) {
{
try {
- // Callback Interface when a channel is connected
+ // Callback Interface when a channel is connected
class ConnectCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
// Callback Interface when a channel is disconnected
class DisconnectCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
// Callback Interface when a channel is reconnected
class ReconnectCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
// Callback Interface when error occurs
class ErrorCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
-
- HashMap<String, Object> args = new HashMap<String, Object>(2);
+
+ HashMap<String, Object> args = new HashMap<String, Object>(2);
args.put("channel", params[0]);
args.put("callback", mPushReceiver);
- args.put("connect_cb", new ConnectCallback()); // callback to get connect event
- args.put("disconnect_cb", new DisconnectCallback()); // callback to get disconnect event
- args.put("reconnect_cb", new ReconnectCallback()); // callback to get reconnect event
- args.put("error_cb", new ErrorCallback()); // callback to get error event
+ args.put("connect_cb", new ConnectCallback()); // callback to get connect event
+ args.put("disconnect_cb", new DisconnectCallback()); // callback to get disconnect event (optional)
+ args.put("reconnect_cb", new ReconnectCallback()); // callback to get reconnect event (optional)
+ args.put("error_cb", new ErrorCallback()); // callback to get error event (optional)
pubnub.subscribe(args);
} catch (Exception e) {
e.printStackTrace();
@@ -647,7 +647,7 @@ public String call() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
HttpUriRequest request = new HttpGet(url);
request.setHeader("V", "3.1");
- request.setHeader("User-Agent", "Android");
+ request.setHeader("User-Agent", "Java-Android");
request.setHeader("Accept-Encoding", "gzip");
httpclient.getParams().setParameter("http.connection.timeout", 310000);
@@ -24,10 +24,9 @@
/** Called when the activity is first created. */
Pubnub pubnub;
- String myMessage="";
+ String myMessage = "", channel = "hello_world";
EditText ed;
RefreshHandler r = new RefreshHandler();
- String channel = "hello_world_rp3";
int limit = 1;
@Override
@@ -52,8 +51,8 @@ public void onClick(View v) {
// Create JSON Message
JSONObject message = new JSONObject();
try {
- if(ed.getText().toString() != null && !ed.getText().toString().equals(""))
- message.put( "Message", ed.getText().toString());
+ if(ed.getText().toString() != null && !ed.getText().toString().equals(""))
+ message.put( "Message", ed.getText().toString());
}
catch (org.json.JSONException jsonError) {}
@@ -79,9 +78,9 @@ public void onClick(View v) {
Android: (Unsubscribe/disconnect)
-------------------------------------------------------------------------------*/
- HashMap<String, Object> args = new HashMap<String, Object>(1);
- args.put("channel", channel);
- pubnub.unsubscribe( args );
+ HashMap<String, Object> args = new HashMap<String, Object>(1);
+ args.put("channel", channel);
+ pubnub.unsubscribe( args );
}
});
@@ -105,15 +104,13 @@ public void onClick(View v) {
JSONArray response = pubnub.history( args );
// Print Response from PubNub JSONP REST Service
- //System.out.println(response);
-
try {
if(response != null){
for (int i = 0; i < response.length(); i++) {
JSONObject jsono = response.optJSONObject(i);
if(jsono != null){
@SuppressWarnings("rawtypes")
- Iterator keys = jsono.keys();
+ Iterator keys = jsono.keys();
while (keys.hasNext()) {
System.out.print(jsono.get( keys.next().toString() ) +" ");
}
@@ -201,6 +198,7 @@ public void AllMessageClick(View v)
response = pubnub.publish(args);
System.out.println(response);
}
+
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
@@ -263,51 +261,51 @@ public boolean execute(Object message) {
// Callback Interface when a channel is connected
class ConnectCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
// Callback Interface when a channel is disconnected
class DisconnectCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
// Callback Interface when a channel is reconnected
class ReconnectCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
// Callback Interface when error occurs
class ErrorCallback implements Callback {
- @Override
- public boolean execute(Object message) {
- System.out.println(message.toString());
- return false;
- }
+ @Override
+ public boolean execute(Object message) {
+ System.out.println(message.toString());
+ return false;
+ }
}
// Listen for Messages (Subscribe)
HashMap<String, Object> args = new HashMap<String, Object>(2);
- args.put("channel", channel); // Channel Name
- args.put("callback", new Receiver()); // callback to get response
- args.put("connect_cb", new ConnectCallback()); // callback to get connect event
- args.put("disconnect_cb", new DisconnectCallback()); // callback to get disconnect event
- args.put("reconnect_cb", new ReconnectCallback()); // callback to get reconnect event
- args.put("error_cb", new ErrorCallback()); // callback to get error event
+ args.put("channel", channel); // Channel Name
+ args.put("callback", new Receiver()); // callback to get response
+ args.put("connect_cb", new ConnectCallback()); // callback to get connect event
+ args.put("disconnect_cb", new DisconnectCallback()); // callback to get disconnect event (optional)
+ args.put("reconnect_cb", new ReconnectCallback()); // callback to get reconnect event (optional)
+ args.put("error_cb", new ErrorCallback()); // callback to get error event (optional)
pubnub.subscribe( args );
} catch (Exception e) {
@@ -325,7 +323,6 @@ protected void onPreExecute() {
protected void onPostExecute(Boolean result) {
// result is the value returned from doInBackground
-
}
}
}
View
@@ -83,9 +83,9 @@ Caveats:
// Publish Message
// Create HashMap parameter
- HashMap<String, Object> args = new HashMap<String, Object>(2);
- args.put("channel", "hello_world"); // Channel Name
- args.put("message", message); // JSON Message
+ HashMap<String, Object> args = new HashMap<String, Object>(2);
+ args.put("channel", "hello_world"); // Channel Name
+ args.put("message", message); // JSON Message
// Publish Message
JSONArray info = pubnub.publish( args );
@@ -115,8 +115,8 @@ Caveats:
// Create HashMap parameter
HashMap<String, Object> args = new HashMap<String, Object>(2);
- args.put("channel", "hello_world"); // Channel Name
- args.put("callback", message_receiver); // Receiver Callback Class
+ args.put("channel", "hello_world"); // Channel Name
+ args.put("callback", message_receiver); // Receiver Callback Class
// Listen for Messages (Subscribe)
pubnub.subscribe( args );
@@ -127,9 +127,9 @@ Caveats:
```java
// Create HashMap parameter
- HashMap<String, Object> args = new HashMap<String, Object>(2);
- args.put("channel", "hello_world"); // Channel Name
-
+ HashMap<String, Object> args = new HashMap<String, Object>(1);
+ args.put("channel", "hello_world"); // Channel Name
+
// Get Unsubscribe
pubnub.unsubscribe( args );
@@ -140,9 +140,9 @@ Caveats:
```java
// Create HashMap parameter
HashMap<String, Object> args = new HashMap<String, Object>(2);
- args.put("channel", "hello_world"); // Channel Name
- args.put("limit", 1); // Limit
-
+ args.put("channel", "hello_world"); // Channel Name
+ args.put("limit", 1); // Limit
+
// Get History
JSONArray response = pubnub.history( args );
@@ -156,13 +156,13 @@ Caveats:
```java
Pubnub pubnub = new Pubnub("demo", "demo");
- System.out.println(" Time: "+pubnub.time());
+ System.out.println(" Time: "+pubnub.time());
```
## Java: (UUID)
```java
- System.out.println(" UUID: "+Pubnub.uuid());
+ System.out.println(" UUID: "+Pubnub.uuid());
```

0 comments on commit 7b36df6

Please sign in to comment.