Skip to content

Commit 47cf418

Browse files
author
Devendra
committed
unsub on permissions error
1 parent 9638eac commit 47cf418

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

  • android/examples/PubnubSubscribe/src/com/pubnub/examples/pubnubsubscribe

‎android/examples/PubnubSubscribe/src/com/pubnub/examples/pubnubsubscribe/PubnubService.java‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class PubnubService extends Service {
3535

3636
public static final String ACTION_FROM_SERVICE = null;
3737

38-
private static final int NOTIFICATION_ID = 1;
38+
private static int NOTIFICATION_ID = 0;
3939

4040
public static String device_channel = "Android-1";
4141
public static String public_channel = "public";
@@ -59,7 +59,11 @@ public static void initPubnub() {
5959
pubnub.setMaxRetries(1000);
6060
}
6161

62-
private void sendNotification(String msg, boolean urgent) {
62+
private void sendNotification(String msg, boolean urgent, int notification_id) {
63+
sendNotification(msg, urgent, notification_id, "Pubnub Notification");
64+
}
65+
66+
private void sendNotification(String msg, boolean urgent, int notifiction_id, String title) {
6367
mNotificationManager = (NotificationManager) this
6468
.getSystemService(Context.NOTIFICATION_SERVICE);
6569

@@ -68,7 +72,7 @@ private void sendNotification(String msg, boolean urgent) {
6872

6973
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
7074
this).setSmallIcon(R.drawable.icon)
71-
.setContentTitle("PubNub Notification")
75+
.setContentTitle(title)
7276
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
7377
.setContentText(msg);
7478

@@ -92,7 +96,7 @@ private void sendNotification(String msg, boolean urgent) {
9296
Log.i("PUBNUB", e.toString());
9397
}
9498
}
95-
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
99+
mNotificationManager.notify(notifiction_id, mBuilder.build());
96100
}
97101

98102
private void notifyUser(JSONObject message) {
@@ -117,7 +121,7 @@ private void notifyUser(JSONObject message) {
117121
intent.putExtra("data", message.toString());
118122
sendBroadcast(intent);
119123
} else {
120-
sendNotification(notification, PubnubActivity.isUrgent(message));
124+
sendNotification(notification, PubnubActivity.isUrgent(message), ++NOTIFICATION_ID);
121125
}
122126

123127
if (data.equals("crash")) {
@@ -158,8 +162,13 @@ public void successCallback(String channel,
158162

159163
@Override
160164
public void errorCallback(String channel,
161-
Object message) {
162-
notifyUser((JSONObject) message);
165+
PubnubError message) {
166+
Log.i("PUBNUB", message.toString());
167+
if (message.errorCode == PubnubError.PNERR_FORBIDDEN) {
168+
pubnub.unsubscribe(device_channel);
169+
sendNotification("Channel : " + device_channel,
170+
true, ++NOTIFICATION_ID, "Permissions Expired");
171+
}
163172
}
164173
});
165174
} catch (PubnubException e) {
@@ -173,8 +182,8 @@ public void successCallback(String channel, Object message) {
173182
}
174183

175184
@Override
176-
public void errorCallback(String channel, Object message) {
177-
notifyUser((JSONObject) message);
185+
public void errorCallback(String channel, PubnubError message) {
186+
Log.i("PUBNUB", message.toString());
178187
}
179188
});
180189
} catch (PubnubException e) {

0 commit comments

Comments
 (0)