1818
1919public class Pubnub extends PubnubCoreShared {
2020
21- String gcmRegistrationId = null ;
2221 /**
2322 * Pubnub Constructor
2423 *
@@ -126,25 +125,53 @@ protected String getUserAgent() {
126125 " Build) PubNub-Java/Android/" + VERSION ;
127126 }
128127
129- public void setGcmRegistrationId (String registrationId ) {
130- this .gcmRegistrationId = registrationId ;
128+
129+ /**
130+ * Enable Push Notifications (Google Cloud Messaging)
131+ * @param channel
132+ * @param gcmRegistrationId
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+ * @param gcmRegistrationId
142+ */
143+ public void enablePushNotificationsOnChannels (String [] channels , String gcmRegistrationId ) {
144+ enablePushNotificationsOnChannels (channels , gcmRegistrationId , null );
145+ }
146+
147+ /**
148+ * Enable Push Notifications (Google Cloud Messaging)
149+ * @param channel
150+ * @param gcmRegistrationId
151+ * @param callback
152+ */
153+ public void enablePushNotificationsOnChannel (String channel , String gcmRegistrationId , Callback callback ) {
154+ enablePushNotificationsOnChannels (new String []{channel }, gcmRegistrationId , callback );
131155 }
132156
133- public void registerDeviceOnChannel (final String channel , final Callback callback ) throws PubnubGcmRegistrationIdMissingException {
134- final Callback cb = getWrappedCallback (callback );
135157
136- if (this .gcmRegistrationId == null || this .gcmRegistrationId .length () <= 0 )
137- throw new PubnubGcmRegistrationIdMissingException ("Registration Id Missing" );
158+ /**
159+ * Enable Push Notifications (Google Cloud Messaging)
160+ * @param channels
161+ * @param gcmRegistrationId
162+ * @param callback
163+ */
164+ public void enablePushNotificationsOnChannels (final String [] channels , String gcmRegistrationId , final Callback callback ) {
165+ final Callback cb = getWrappedCallback (callback );
138166
139167 Hashtable parameters = PubnubUtil .hashtableClone (params );
140168 String [] urlargs = null ;
141169 urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
142- this .SUBSCRIBE_KEY , "devices" , this . gcmRegistrationId
170+ this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId
143171 };
144172
145-
146173 parameters .put ("type" , "gcm" );
147- parameters .put ("add" , channel );
174+ parameters .put ("add" , PubnubUtil . joinString ( channels , "," ) );
148175
149176 HttpRequest hreq = new HttpRequest (urlargs , parameters ,
150177 new ResponseHandler () {
@@ -168,21 +195,58 @@ public void handleError(HttpRequest hreq, PubnubError error) {
168195
169196 _request (hreq , nonSubscribeManager );
170197 }
171- public void unregisterDeviceFromChannel (final String channel , final Callback callback ) throws PubnubGcmRegistrationIdMissingException {
198+
199+ /**
200+ * Disable Push Notifications (Google Cloud Messaging)
201+ * @param channel
202+ * @param gcmRegistrationId
203+ */
204+ public void disablePushNotificationsOnChannel (String channel , String gcmRegistrationId ) {
205+ disablePushNotificationsOnChannels (new String []{channel }, gcmRegistrationId , null );
206+ }
207+
208+ /**
209+ * Disable Push Notifications (Google Cloud Messaging)
210+ * @param channels
211+ * @param gcmRegistrationId
212+ */
213+ public void disablePushNotificationsOnChannels (String [] channels , String gcmRegistrationId ) {
214+ disablePushNotificationsOnChannels (channels , gcmRegistrationId , null );
215+ }
216+
217+ /**
218+ * Disable Push Notifications (Google Cloud Messaging)
219+ * @param channel
220+ * @param gcmRegistrationId
221+ * @param callback
222+ */
223+ public void disablePushNotificationsOnChannel (String channel , String gcmRegistrationId , Callback callback ) {
224+ disablePushNotificationsOnChannels (new String []{channel }, gcmRegistrationId , callback );
225+ }
226+
227+ /**
228+ * Disable Push Notifications (Google Cloud Messaging)
229+ * @param channel
230+ * @param callback
231+ */
232+ /**
233+ * @param channels
234+ * @param gcmRegistrationId
235+ * @param callback
236+ */
237+ public void disablePushNotificationsOnChannels (final String [] channels , String gcmRegistrationId , final Callback callback ) {
172238 final Callback cb = getWrappedCallback (callback );
173239
174- if (this .gcmRegistrationId == null || this .gcmRegistrationId .length () <= 0 )
175- throw new PubnubGcmRegistrationIdMissingException ("Registration Id Missing" );
176240
177241 Hashtable parameters = PubnubUtil .hashtableClone (params );
178242 String [] urlargs = null ;
179243 urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
180- this .SUBSCRIBE_KEY , "devices" , this . gcmRegistrationId
244+ this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId
181245 };
182246
183247
184248 parameters .put ("type" , "gcm" );
185- parameters .put ("remove" , channel );
249+ parameters .put ("remove" , PubnubUtil . joinString ( channels , "," ) );
186250
187251 HttpRequest hreq = new HttpRequest (urlargs , parameters ,
188252 new ResponseHandler () {
@@ -206,12 +270,19 @@ public void handleError(HttpRequest hreq, PubnubError error) {
206270
207271 _request (hreq , nonSubscribeManager );
208272 }
209- public void getChannelListforDevice (final Callback callback ) {
273+
274+
275+ /**
276+ * Get channels for which push notification is enabled (Google Cloud Messaging)
277+ * @param gcmRegistrationId
278+ * @param callback
279+ */
280+ public void requestPushNotificationEnabledChannelsForDeviceRegistrationId (String gcmRegistrationId , final Callback callback ) {
210281 final Callback cb = getWrappedCallback (callback );
211282 Hashtable parameters = PubnubUtil .hashtableClone (params );
212283 String [] urlargs = null ;
213284 urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
214- this .SUBSCRIBE_KEY , "devices" , this . gcmRegistrationId
285+ this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId
215286 };
216287
217288
@@ -237,12 +308,26 @@ public void handleError(HttpRequest hreq, PubnubError error) {
237308 }
238309 });
239310 }
240- public void unregisterAllChannelsForDevice (final Callback callback ) {
311+
312+ /**
313+ * Disable push notifications for all channels (Google Cloud Messaging)
314+ * @param gcmRegistrationId
315+ */
316+ public void removeAllPushNotificationsForDeviceRegistrationId (String gcmRegistrationId ) {
317+ removeAllPushNotificationsForDeviceRegistrationId (gcmRegistrationId , null );
318+ }
319+
320+ /**
321+ * Disable push notifications for all channels (Google Cloud Messaging)
322+ * @param gcmRegistrationId
323+ * @param callback
324+ */
325+ public void removeAllPushNotificationsForDeviceRegistrationId (String gcmRegistrationId , final Callback callback ) {
241326 final Callback cb = getWrappedCallback (callback );
242327 Hashtable parameters = PubnubUtil .hashtableClone (params );
243328 String [] urlargs = null ;
244329 urlargs = new String []{ getPubnubUrl (), "v1" , "push" , "sub-key" ,
245- this .SUBSCRIBE_KEY , "devices" , this . gcmRegistrationId , "remove"
330+ this .SUBSCRIBE_KEY , "devices" , gcmRegistrationId , "remove"
246331 };
247332
248333
0 commit comments