3535** Now we can register callbacks that our app will react to, these are just plain integers (They should be unique!).**
3636
3737``` java
38- // Create your own callback id, random number. Make sure they don't have the same values as any of the Pubsub constants.
39- private int MY_OWN_CALLBACK = 6322 ;
38+ // Create your own callback id, random number. Make sure they don't have the same values as any of the Pubsub constants.
39+ private int MY_OWN_CALLBACK = 6322 ;
4040
41- // Use our new callback id to subscribe to specific events on the sub
42- JSONObject json_filter = new JSONObject ();
41+ // Use our new callback id to subscribe to specific events on the sub
42+ JSONObject json_filter = new JSONObject ();
4343
44- // Our filter is currently looking for version numbers that are GREATER THAN 0.1!
45- try {
46- JSONObject version = new JSONObject ();
47- version. put(" $gt" , 0.1 );
44+ // Our filter is currently looking for version numbers that are GREATER THAN 0.1!
45+ try {
46+ JSONObject version = new JSONObject ();
47+ version. put(" $gt" , 0.1 );
4848
49- json_filter. put(" version" , version);
50- } catch (JSONException e) {
51- e. printStackTrace();
52- }
49+ json_filter. put(" version" , version);
50+ } catch (JSONException e) {
51+ e. printStackTrace();
52+ }
5353
54- mPubsub. subscribe(json_filter, VERSION_FILTER );
54+ mPubsub. subscribe(json_filter, VERSION_FILTER );
5555```
5656
5757** Then, create the Handler. This will act as a message callback between the Service and your Activity.**
@@ -73,7 +73,7 @@ private int MY_OWN_CALLBACK = 6322;
7373 // TODO Read error messages here...
7474 break ;
7575 case MY_OWN_CALLBACK :
76- try {
76+ try {
7777 double version = doc. getDouble(" version" );
7878 Log . i(TAG , " Version message from Pubsub.io: " + version);
7979 } catch (JSONException e) {
@@ -110,7 +110,7 @@ try {
110110 }
111111```
112112
113- ## Also, you must make sure NOT to forget your AndroidManifest, it's imperative that you make the following two changes!
113+ ## Also, you must make sure NOT to forget your AndroidManifest, it's imperative that you make the following changes!
114114
115115* Add a <service > tag that points to the Pubsub service, otherwise you can't connect to it.
116116* Add a <uses-permission > tag with the INTERNET rule.
0 commit comments