@@ -123,256 +123,4 @@ protected String getUserAgent() {
123123 " Build) PubNub-Java/Android/" + VERSION ;
124124 }
125125
126-
127- /**
128- * Enable Push Notifications (Google Cloud Messaging)
129- * @param channel
130- * Channel for which to enable push notifications
131- * @param gcmRegistrationId
132- * Google Cloud Messaging registration id
133- */
134- public void enablePushNotificationsOnChannel (String channel , String gcmRegistrationId ) {
135- enablePushNotificationsOnChannels (new String []{channel }, gcmRegistrationId , null );
136- }
137-
138- /**
139- * Enable Push Notifications (Google Cloud Messaging)
140- * @param channels
141- * Channels for which to enable push notifications
142- * @param gcmRegistrationId
143- * Google Cloud Messaging registration id
144- */
145- public void enablePushNotificationsOnChannels (String [] channels , String gcmRegistrationId ) {
146- enablePushNotificationsOnChannels (channels , gcmRegistrationId , null );
147- }
148-
149- /**
150- * Enable Push Notifications (Google Cloud Messaging)
151- * @param channel
152- * Channel for which to enable push notifications
153- * @param gcmRegistrationId
154- * Google Cloud Messaging registration id
155- * @param callback
156- * Callback object
157- */
158- public void enablePushNotificationsOnChannel (String channel , String gcmRegistrationId , Callback callback ) {
159- enablePushNotificationsOnChannels (new String []{channel }, gcmRegistrationId , callback );
160- }
161-
162-
163- /**
164- * Enable Push Notifications (Google Cloud Messaging)
165- * @param channels
166- * Channels for which to enable push notifications
167- * @param gcmRegistrationId
168- * Google Cloud Messaging registration id
169- * @param callback
170- * Callback object
171- */
172- public void enablePushNotificationsOnChannels (final String [] channels , String gcmRegistrationId , final Callback callback ) {
173- final Callback cb = getWrappedCallback (callback );
174-
175- Hashtable parameters = PubnubUtil .hashtableClone (params );
176- String [] urlargs = null ;
177- urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
178- this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId
179- };
180-
181- parameters .put ("type" , "gcm" );
182- parameters .put ("add" , PubnubUtil .joinString (channels , "," ));
183-
184- HttpRequest hreq = new HttpRequest (urlargs , parameters ,
185- new ResponseHandler () {
186- public void handleResponse (HttpRequest hreq , String response ) {
187- JSONArray jsarr ;
188- try {
189- jsarr = new JSONArray (response );
190- } catch (JSONException e ) {
191- handleError (hreq ,
192- PubnubError .getErrorObject (PubnubError .PNERROBJ_INVALID_JSON , 1 , response ));
193- return ;
194- }
195- cb .successCallback ("" , jsarr );
196- }
197-
198- public void handleError (HttpRequest hreq , PubnubError error ) {
199- cb .errorCallback ("" , error );
200- return ;
201- }
202- });
203-
204- _request (hreq , nonSubscribeManager );
205- }
206-
207- /**
208- * Disable Push Notifications (Google Cloud Messaging)
209- * @param channel
210- * Channel for which to disable push notifications
211- * @param gcmRegistrationId
212- * Google Cloud Messaging registration id
213- */
214- public void disablePushNotificationsOnChannel (String channel , String gcmRegistrationId ) {
215- disablePushNotificationsOnChannels (new String []{channel }, gcmRegistrationId , null );
216- }
217-
218- /**
219- * Disable Push Notifications (Google Cloud Messaging)
220- * @param channels
221- * Channels for which to disable push notifications
222- * @param gcmRegistrationId
223- * Google Cloud Messaging registration id
224- */
225- public void disablePushNotificationsOnChannels (String [] channels , String gcmRegistrationId ) {
226- disablePushNotificationsOnChannels (channels , gcmRegistrationId , null );
227- }
228-
229- /**
230- * Disable Push Notifications (Google Cloud Messaging)
231- * @param channel
232- * @param gcmRegistrationId
233- * @param callback
234- */
235- public void disablePushNotificationsOnChannel (String channel , String gcmRegistrationId , Callback callback ) {
236- disablePushNotificationsOnChannels (new String []{channel }, gcmRegistrationId , callback );
237- }
238-
239- /**
240- * Disable Push Notifications (Google Cloud Messaging)
241- * @param channel
242- * @param callback
243- */
244- /**
245- * @param channels
246- * Channels for which to disable push notifications
247- * @param gcmRegistrationId
248- * Google Cloud Messaging registration id
249- * @param callback
250- * Callback object
251- */
252- public void disablePushNotificationsOnChannels (final String [] channels , String gcmRegistrationId , final Callback callback ) {
253- final Callback cb = getWrappedCallback (callback );
254-
255-
256- Hashtable parameters = PubnubUtil .hashtableClone (params );
257- String [] urlargs = null ;
258- urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
259- this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId
260- };
261-
262-
263- parameters .put ("type" , "gcm" );
264- parameters .put ("remove" , PubnubUtil .joinString (channels , "," ));
265-
266- HttpRequest hreq = new HttpRequest (urlargs , parameters ,
267- new ResponseHandler () {
268- public void handleResponse (HttpRequest hreq , String response ) {
269- JSONArray jsarr ;
270- try {
271- jsarr = new JSONArray (response );
272- } catch (JSONException e ) {
273- handleError (hreq ,
274- PubnubError .getErrorObject (PubnubError .PNERROBJ_INVALID_JSON , 1 , response ));
275- return ;
276- }
277- cb .successCallback ("" , jsarr );
278- }
279-
280- public void handleError (HttpRequest hreq , PubnubError error ) {
281- cb .errorCallback ("" , error );
282- return ;
283- }
284- });
285-
286- _request (hreq , nonSubscribeManager );
287- }
288-
289-
290- /**
291- * Get channels for which push notification is enabled (Google Cloud Messaging)
292- * @param gcmRegistrationId
293- * Google Cloud Messaging registration id
294- * @param callback
295- * Callback object
296- */
297- public void requestPushNotificationEnabledChannelsForDeviceRegistrationId (String gcmRegistrationId , final Callback callback ) {
298- final Callback cb = getWrappedCallback (callback );
299- Hashtable parameters = PubnubUtil .hashtableClone (params );
300- String [] urlargs = null ;
301- urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
302- this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId
303- };
304-
305-
306- parameters .put ("type" , "gcm" );
307-
308- HttpRequest hreq = new HttpRequest (urlargs , parameters ,
309- new ResponseHandler () {
310- public void handleResponse (HttpRequest hreq , String response ) {
311- JSONArray jsarr ;
312- try {
313- jsarr = new JSONArray (response );
314- } catch (JSONException e ) {
315- handleError (hreq ,
316- PubnubError .getErrorObject (PubnubError .PNERROBJ_INVALID_JSON , 1 , response ));
317- return ;
318- }
319- cb .successCallback ("" , jsarr );
320- }
321-
322- public void handleError (HttpRequest hreq , PubnubError error ) {
323- cb .errorCallback ("" , error );
324- return ;
325- }
326- });
327- _request (hreq , nonSubscribeManager );
328- }
329-
330- /**
331- * Disable push notifications for all channels (Google Cloud Messaging)
332- * @param gcmRegistrationId
333- * Google Cloud Messaging registration id
334- */
335- public void removeAllPushNotificationsForDeviceRegistrationId (String gcmRegistrationId ) {
336- removeAllPushNotificationsForDeviceRegistrationId (gcmRegistrationId , null );
337- }
338-
339- /**
340- * Disable push notifications for all channels (Google Cloud Messaging)
341- * @param gcmRegistrationId
342- * Google Cloud Messaging registration id
343- * @param callback
344- * Callback object
345- */
346- public void removeAllPushNotificationsForDeviceRegistrationId (String gcmRegistrationId , final Callback callback ) {
347- final Callback cb = getWrappedCallback (callback );
348- Hashtable parameters = PubnubUtil .hashtableClone (params );
349- String [] urlargs = null ;
350- urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
351- this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId , "remove"
352- };
353-
354-
355- parameters .put ("type" , "gcm" );
356-
357- HttpRequest hreq = new HttpRequest (urlargs , parameters ,
358- new ResponseHandler () {
359- public void handleResponse (HttpRequest hreq , String response ) {
360- JSONArray jsarr ;
361- try {
362- jsarr = new JSONArray (response );
363- } catch (JSONException e ) {
364- handleError (hreq ,
365- PubnubError .getErrorObject (PubnubError .PNERROBJ_INVALID_JSON , 1 , response ));
366- return ;
367- }
368- cb .successCallback ("" , jsarr );
369- }
370-
371- public void handleError (HttpRequest hreq , PubnubError error ) {
372- cb .errorCallback ("" , error );
373- return ;
374- }
375- });
376- _request (hreq , nonSubscribeManager );
377- }
378126}
0 commit comments